在悬停中使用 jquery 启动和停止计时器
你们如何在停止后重新启动 JavaScript 计时器。基本上我需要计时器停止,然后在推出 div 时重新开始。我有
var time = setInterval(myFunction, 1000);
计时器
function myFunction(){<br/>
if(){
do this
}
else if () {
do this
}
};
然后我
$("td").hover(
function () {
window.clearInterval()
},<br/>
function () {
timer
}
);
一切正常,除了它不会在悬停关闭时再次启动。如果我将一个新的计时器置于悬停状态,则每次您悬停和关闭时计时器都会开始加速......任何想法。 谢谢
how would you guys reinitiate a javascript timer after it's been stopped. Basically I need the timer to stop, and then start again on rollout of a div. I have
var timer = setInterval(myFunction, 1000);
timer
function myFunction(){<br/>
if(){
do this
}
else if () {
do this
}
};
then I have
$("td").hover(
function () {
window.clearInterval()
},<br/>
function () {
timer
}
);
all works good except it doesn't start again on hover off. If I put a new timer in hover off the timer starts to speed up every time you hover on and off.... Any ideas.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解释:发生的情况是 setInterval 返回与该间隔关联的ID。
我做了一个littse jsFiddle 来展示它的工作原理。
注意:这不会暂停当前的间隔。它会停止它并再次启动它。因此,如果您在 9 秒处以 10 秒为间隔并停止它。当再次启动时,还需要 10 秒。
Explanation: What's happening is that the setInterval is returning the ID associated with that interval.
I did a littse jsFiddle to show it works.
NOTE: this doesn't pause the current Interval. It stops it and starts it again. So if you were in a 10sec interval at 9 secs and stopped it. When it starts again it will take another 10secs.