所以我有这个代码:
$(document).ready(function(){
$("#slideshow > div:gt(0)").hide();
setInterval(function() {
$("#slideshow > div:first")
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo("#slideshow");
}, 3000);
});
Run Code Online (Sandbox Code Playgroud)
100%正常工作..我在哪里添加.hover()幻灯片的功能暂停悬停?
方法setInterval()返回一个intervalID,您可以使用clearInterval()清除当前间隔/超时.
你可以这样做:
$(document).ready(function() {
var timer;
$("#slideshow > div:gt(0)").hide();
$("#slideshow")
// when mouse enters, clear the timer if it has been set
.mouseenter(function() {
if (timer) { clearInterval(timer) }
})
// when mouse goes out, start the slideshow
.mouseleave(function() {
timer = setInterval(function() {
$("#slideshow > div:first")
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo("#slideshow");
}, 3000);
})
// trigger mouseleave for initial slideshow starting
.mouseleave();
});?
Run Code Online (Sandbox Code Playgroud)