gpt4 book ai didi

jquery - 如何通过window.scroll设置幻灯片切换

转载 作者:行者123 更新时间:2023-12-01 04:40:34 24 4
gpt4 key购买 nike

我想在滚动处于特定高度时运行或停止幻灯片放映。

但它总是运行。

如何修复它?

谢谢

 $(document).ready(function() {
var timer, _showSpeed = 3000, _stop = false;
setTimeout(autoPlay, _showSpeed);

function autoPlay(){
if($('a[href="#index"]').parent().hasClass('active')){
$('.center:eq(0) .arrow.right').click();
}else if($('a[href="#favorable"]').parent().hasClass('active')){
$('.center:eq(1) .arrow.right').click();
}

setTimeout(autoPlay, _showSpeed);
return false;
}

$(window).scroll(function() {
scrollTop = $(window).scrollTop();
if(scrollTop > 80 ){
_stop = true;
timer = setTimeout(autoPlay, _showSpeed);
clearTimeout(timer);
}
else{
_stop = false;
clearTimeout(timer);
}
console.log(_stop);
});

});

最佳答案

您可以尝试使用以下代码吗:

$(document).ready(function() {
var timer, _showSpeed = 3000,
_stop = false;
timer = setTimeout(autoPlay, _showSpeed);

function autoPlay() {
if(_stop)
return;

if ($('a[href="#index"]').parent().hasClass('active')) {
$('.center:eq(0) .arrow.right').click();
} else if ($('a[href="#favorable"]').parent().hasClass('active')) {
$('.center:eq(1) .arrow.right').click();
}

timer = setTimeout(autoPlay, _showSpeed);
return false;
}

$(window).scroll(function() {
scrollTop = $(window).scrollTop();
if (scrollTop > 80) {
_stop = true;
clearTimeout(timer);
} else {
_stop = false;
timer = setTimeout(autoPlay, _showSpeed);
}
console.log(_stop);
});

});

关于jquery - 如何通过window.scroll设置幻灯片切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38738257/

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