这是我的代码
<body>
<div id="slideshow">
<div>
<img src="assets/images/home-banner.jpg" width="995" height="421" alt=""/>
</div>
<div>
<img src="assets/images/banner1.jpg" width="995" height="421" alt=""/>
</div>
<div>
<img src="assets/images/home-banner.jpg" width="995" height="421" alt=""/>
</div>
<div>
<img src="assets/images/banner1.jpg" width="995" height="421" alt=""/>
</div>
</div>
<script>
$("#slideshow > div:gt(0)").hide();
setInterval(function() {
$('#slideshow > div:first')
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo('#slideshow');
}, 3000);
</script>
</body>
最佳答案
首先,很难用您的代码来完成它,它应该被重新格式化为一个函数,作为滑动图像的角色,让我们假设该函数的名称为animate_slider(),要在鼠标悬停时停止它,只需设置clearInterval准时参数是这样的:
var time=setInterval("animate_slider()",3000);
$('div#slideshow').mouseover(function(){
clearInterval(time);
});
关于jquery - 如何创建在鼠标悬停时停止的图像滑块?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36687388/