我要上悬停图像滑块暂停。 这是我的代码jQuery的:暂停图像上滑动悬停
$(".col-md-8").hover(function() {
clearTimeout(timer);
});
在我看来是正确的,但出了问题。什么是问题?提前致谢。
我要上悬停图像滑块暂停。 这是我的代码jQuery的:暂停图像上滑动悬停
$(".col-md-8").hover(function() {
clearTimeout(timer);
});
在我看来是正确的,但出了问题。什么是问题?提前致谢。
看看这个Pen
var nextimage = 0;
var timer = 0;
doSlideshow();
function doSlideshow() {
if (nextimage >= images.length) {
nextimage = 0;
}
$('.col-md-8').css('background-image', 'url("' + images[nextimage++] + '")').fadeIn(3000, function() {
timer = setTimeout(doSlideshow, 3000);
});
}
$(".col-md-8").hover(function() {
clearTimeout(timer);
});
$(".col-md-8").mouseout(function() {
setTimeout(doSlideshow, 3000);
});
var elems = document.getElementsByClassName("col-md-8");
for (var i = 0; i < elems.length; i++) {
elems[i].style.backgroundRepeat = "no-repeat";
elems[i].style.backgroundSize = "100%";
}
我感谢你的帮助。顺便说一句,你为什么创建计时器并分配到零? – NZMAI
您分配了timer = setTimeout(doSlideshow,3000);它总是返回1.如果将其设置为0,它将精确返回定时器值。然后我们可以清除计时器 – cheralathan
见http://stackoverflow.com/questions/38334119/autorunning-css-change/ – guest271314