gpt4 book ai didi

jquery - 在 setInterval() 中添加悬停暂停?

转载 作者:行者123 更新时间:2023-12-03 22:28:21 26 4
gpt4 key购买 nike

您好,这是我的用于幻灯片放映的 jquery 函数以及其他内置函数。当我将鼠标悬停在整个 div 上时,我一直试图让它暂停。帮帮我吧!

$(function() {
var timer = setInterval( showDiv, 5000);
var counter = 2;
function showDiv() {

if (counter ==0) { counter++; return; }

$('div','#slide-show-overall')
.stop()
.fadeOut('slow')
.filter( function() { return this.id.match('picture-set-' + counter); })
.fadeIn('slow');
if (counter ==2) { slideWings();} //extra functions
if (counter ==1) { resetWings();} //extra functions
counter == 3? counter = 1 : counter++;
}
});
});



<div style="position:absolute;width:1000px;height:600;top:0px;z-index:0;overflow:hidden;" id="slide-show-overall" >
<div id="picture-set-1" style="">
<img src="images/3.jpg" align=left width=1000>
</div>
<div id="picture-set-2" style="display:none;">
<img src="images/1.jpg" align=left width=1000>
<img src="images/wing_left.png" align=left height=200 width=200 style="margin-top:-900px;margin-left:230px;" id="wing-left-1">
<img src="images/wing_right.png" align=left height=200 width=200 style="margin- top:-900px;margin-left:830px;" id="wing-right-1">
</div>
<div id="picture-set-3" style="display:none;">
<img src="images/5.jpg" align=left width=1000>
</div>
</div>

最佳答案

您想要使用 clearInterval 删除悬停时的间隔,然后在关闭悬停功能中替换它:

$('#slide-show-overall').hover(function(ev){
clearInterval(timer);
}, function(ev){
timer = setInterval( showDiv, 5000);
});

关于jquery - 在 setInterval() 中添加悬停暂停?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10913703/

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