如何暂停setTimeout调用? [英] How to pause a setTimeout call?

查看:1586
本文介绍了如何暂停setTimeout调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

javascript:pause setTimeout();

我正在使用jQuery并在我的网站的通知系统。通知使用setTimeout函数自动淡出。

Im using jQuery and working on a notification system for my site. The notifications automatically fadeout using the setTimeout function.

如何停止setTimeout调用的计时器?

How can i stop the timer of the setTimeout call?

例如,我希望在鼠标悬停在通知上时暂停setTimeout调用并继续向下计数鼠标...

For example i would like to pause the setTimeout call while the mouse is over the notification and continue the count down mouseout...

我用谷歌搜索暂停setTimeout没有运气。

I googled "pause setTimeout" with no luck.

我正在使用clearTimeout清除setTimeout调用,同时淡出mouseout上的通知但是暂停效果会很好。

Im currently clearing the setTimeout call with clearTimeout and at same time fading out the notification on mouseout but it would be nice to have that pause effect.

任何想法?

推荐答案

试试这个。

var myTimeOut;
$(someElement).mouseout( function () {
  myTimeOut = setTimeout("mytimeoutfunction()", 5000)
});

$(someElement).mouseover( function () {
  clearTimeout(myTimeOut);
});

这篇关于如何暂停setTimeout调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆