<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>判断浏览当前页面倒计时几秒</title>
<meta name="keywords" content="">
<meta name="description" content="">
<script src="js/jquery-3.2.1.min.js"></script>
<style>
*{
margin: 0;
padding: 0;
}
.times{
height: 2000px;
text-align: center;
line-height: 500px;
font-size: 50px;
}
</style>
</head>
<body>
<div class="times">
8
</div>
<script>
$(function () {
var timer = null;
var num = 7;
var _move = true;
$(document).on('visibilitychange', function(e) {
if (e.target.visibilityState === "visible") {
_move = true;
fn()
} else if (e.target.visibilityState === "hidden") {
clearInterval(timer);
}
});
function fn() {
$(window).scroll(function () {
if (_move) {
_move = false;
timer=setInterval(function () {
if (num==0){
clearInterval(timer);
}else {
$('.times').html(num)
num--
}
},1000)
}
})
}
fn()
})
</script>
</body>
</html>
判断浏览当前页面倒计时几秒
最新推荐文章于 2023-08-15 14:32:00 发布