我知道这个问题已被提出并得到解答 here已经,但是设置计时器可以使用hover()函数。
由于我的元素是动态创建的,因此它需要两个不同的函数:一个在 mouseenter 上,另一个在 mouseleave 上。
有人对这个特殊需求有深入的了解吗?
PS:我知道有一个名为hoverIntent的插件,但我不想使用任何插件!
最佳答案
尝试
$(document).on({
mouseenter: function () {
var $this = $(this);
var timer = setTimeout(function () {
$this.click();
}, 2000)
$this.data('clicktimer', timer)
},
mouseleave: function () {
clearTimeout($(this).data('clicktimer'))
}
}, '#test');
演示:Fiddle
关于javascript - 如何使用 JQuery 将鼠标悬停在元素上 x 秒时触发点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18943579/