我想在屏幕滚动的时候把_time设为零,就是立马让p为hide(),而不是关闭定时器
这样能做吗?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
<body>
<input type="button" value="点击" class="show"/>
<p class="dis">hello</p>
<script>
$(function(){
var _time = 3000;
$('.show').click(function(){
timer3 = setTimeout(function(){
$(".dis").hide();
},_time);
})
window.scroll(function(){
})
})
</script>
</body>
</html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
直接在屏幕滚动的时候,将
phide()不就行了吗,一定要用定时器兜个圈子吗?哪位给编辑过了
如果你的timer3已经在执行了,你在设置_time为0,应该是不行的。
为什么不直接在滚动时直接设置$(".dis").hide();了?
clear掉定时器就行了,然后$(".dis").hide();
不行,你调用一次的setTimeout函数就是往JS的定时器执行队列中注册了一个定时器,除非调用clearTimeout函数,否则你是清除不掉定时器的~~