本文介绍了在setInterval()上添加悬停功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,这是我的jquery函数,用于与其他内置函数进行幻灯片放映.当我将鼠标悬停在整个div上时,我一直试图使其暂停.帮帮我!
Hi here's my jquery function for slideshow with other inbuilt function.I have been trying to make it pause when i hover over the overall div. Help me out!
$(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
删除悬停时的间隔,然后将其替换为悬停"功能:
You want to use clearInterval
to remove the interval on hover and then replace it in the off hover function:
$('#slide-show-overall').hover(function(ev){
clearInterval(timer);
}, function(ev){
timer = setInterval( showDiv, 5000);
});
这篇关于在setInterval()上添加悬停功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!