gpt4 book ai didi

javascript - 如何在悬停时暂停幻灯片放映

转载 作者:行者123 更新时间:2023-11-29 10:48:14 24 4
gpt4 key购买 nike

当我将鼠标悬停在 jQuery 幻灯片中的图像上时,如何添加暂停效果?

$(document).ready(function () {
slideShow();
});

function slideShow() {
var showing = $('#slideshow .show');
var next = showing.next().length ? showing.next() : showing.parent().children(':first');
var timer;
showing.fadeOut(500, function () {
next.fadeIn(200).addClass('show');
}).removeClass('show');
setTimeout(slideShow, 3000);
}

最佳答案

var hovering = false;               //default is not hovering
$("#slideshow").hover(function () { //*replace body with your element
hovering = true; //when hovered, hovering is true
}, function () {
hovering = false; //when un-hovered, hovering is false
slideShow(); //start the process again
});

function slideShow() {
if(!hovering) { //if not hovering, proceed
/* Your code here*/
nextSlide();
setTimeout(slideShow, 1000);
}
}

function nextSlide(){
var showing = $('#slideshow .show');
var next = showing.next().length ? showing.next() : showing.parent().children(':first');
var timer;
showing.fadeOut(500, function () {
next.fadeIn(200).addClass('show');
}).removeClass('show');
}

演示: http://jsfiddle.net/DerekL/mqEbZ/

关于javascript - 如何在悬停时暂停幻灯片放映,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15376808/

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