gpt4 book ai didi

jQuery setInterval/悬停 : it works once, 但随后停止 setInterval

转载 作者:行者123 更新时间:2023-12-01 03:25:31 26 4
gpt4 key购买 nike


我的“setInterval”函数有问题,我想在将鼠标悬停在 div 上时启动该函数,但是 setInterval 在我将鼠标悬停在 div 上时第一次起作用=>如果我停留在div,它不会继续改变图片,而是停止'setinterval'。

是mouseenter的问题吗?我尝试过“悬停”等,但似乎没有任何效果。

有人有解决办法吗?

非常感谢您的帮助,这是我的代码:

img.bind('mouseenter', function(){
setInterval(next($(this)),1000);
});

function next(elem){
var img_li = elem.find('li');
count++;
if (count>2) count=0;

img_li.eq(count).fadeIn('fast', function(){
img_li.eq(current).css({'display':'none'});

current = count;
});
}

最佳答案

这是因为您将 next($(this)) 的返回值分配给 setInterval 而不是函数本身。

试试这个:

img.bind('mouseenter', function(){     
var that = $(this); //Use that-this model to avoid any scope issues with this reference
setInterval(function(){
next(that);
},1000);
});

关于jQuery setInterval/悬停 : it works once, 但随后停止 setInterval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5622076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com