组合键使用,全屏,退出全屏检测
var num = 5;
var num1 = 0;
var flag = true;//是否失去焦点
var size;//是否全屏状态
var live;//是否离开超过了5秒
var change = function () {
if (num <= 0) {
console.log('提交试卷,弹窗提示')
$('.tishi2').show();
$('.tishi1').hide();
} else {
console.log(live, 'live')
if (live) {
console.log('页面激活');
} else {
console.log('页面非激活');
$('.tishi1').show();
num--
num1++
$('.num').html(num1)
}
}
}
// 定时器
var time = function () {
console.log('进入定时器')
clearTimeout(timer1);
var timer1 = setTimeout(function () {
change()
}, 5000)
}
// ESC退出全屏
window.onresize = function () {
console.log(size, 'size')
if (!size) {
size = true;
live = true;
} else {
live = false;
size = false;
console.log('退出全屏')
time()
}
}
// 键盘组合键按下事件
// $(window).keydown(function (event) {
// var e = event;
// var keyCode = e.keyCode || e.which || e.charCode;
// var allKey = e.ctrlKey || e.metaKey || e.shiftKey || e.altKey;
// if (allKey && keyCode == 115) {
// // event.preventDefault()
// alert("组合键成功")
// return false;
// } else if (allKey && (keyCode == 37 || keyCode == 39)) {
// alert("不准你使用ALT+方向键前进或后退网页!");
// time()
// return false;
// }
// });
// 全屏
$('.btn').click(function () {
var elem = document.getElementById("content");
requestFullScreen(elem);
flag = false;
size = false;
})
function requestFullScreen(element) {
var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
requestMethod.call(element);
}
window.onblur = function () {
console.log('失去焦点')
if (flag) {
flag = false;
live = false;
console.log(flag, 'flag失去焦点')
time()
}
}
window.onfocus = function () {
console.log('获得焦点')
flag = true;
live = true;
console.log(flag, 'flag')
}