如何为jquery mouseover添加延迟? [英] How to add delay to jquery mouseover?
本文介绍了如何为jquery mouseover添加延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个页面上有一堆图像,我使用以下内容触发事件:
I have a bunch of images on one page and I am using the following to trigger an event:
$('.img').on('mouseover', function() {
//do something
});
是否有某种方法可以添加延迟,如果用户徘徊1秒钟,那么//做某事或实际触发鼠标悬停事件?
Is there some way to add a delay such that if a user hovers for maybe 1 second, then it does "//do something" or actually triggers the "mouseover" event?
推荐答案
您可以使用 setTimeout
var delay=1000, setTimeoutConst;
$('.img').on('hover', function() {
setTimeoutConst = setTimeout(function() {
// do something
}, delay);
}, function() {
clearTimeout(setTimeoutConst);
});
这篇关于如何为jquery mouseover添加延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文