在 jQuery 中推进幻灯片放映

发布于 2024-12-07 17:05:24 字数 859 浏览 1 评论 0 原文

我使用教程杂志中的这段代码:

$(window).load(function(){

    // The window.load event guarantees that all the images are loaded before the auto-advance begins.
    var timeOut = null;

    $('#slider_navigator .arrow, #slider_navigator .dot').click(function(e,simulated){
        // The simulated parameter is set by the trigger method.
        if(!simulated){
            // A real click occured. Cancel the auto advance animation.
            clearTimeout(timeOut);
        }
    });

    // A self executing named function expression:
    (function autoAdvance(){
        // Simulating a click on the next arrow.
        timeOut = setTimeout(autoAdvance,2000);
        $('.slider_rightlink').trigger('click',[true]);
    })();

});

这与预期的一样,除了一件事之外,当我加载页面时,第一张幻灯片立即前进。加载后,它可以与幻灯片的其余部分很好地旋转。

我该如何更改它,使其像其他幻灯片一样显示第一张幻灯片 2 秒?

I use this piece of code from tutorialzine:

$(window).load(function(){

    // The window.load event guarantees that all the images are loaded before the auto-advance begins.
    var timeOut = null;

    $('#slider_navigator .arrow, #slider_navigator .dot').click(function(e,simulated){
        // The simulated parameter is set by the trigger method.
        if(!simulated){
            // A real click occured. Cancel the auto advance animation.
            clearTimeout(timeOut);
        }
    });

    // A self executing named function expression:
    (function autoAdvance(){
        // Simulating a click on the next arrow.
        timeOut = setTimeout(autoAdvance,2000);
        $('.slider_rightlink').trigger('click',[true]);
    })();

});

This works like expected except one thing, the first slide is immediately advanced when I load the page. After loading it rotates nicely with the rest of the slides.

How can I change this so that it shows the first slide 2 seconds like the rest?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧故 2024-12-14 17:05:24
$(window).load(function(){setTimeout(function(){

    // The window.load event guarantees that all the images are loaded before the auto-advance begins.
    var timeOut = null;

    $('#slider_navigator .arrow, #slider_navigator .dot').click(function(e,simulated){
        // The simulated parameter is set by the trigger method.
        if(!simulated){
            // A real click occured. Cancel the auto advance animation.
            clearTimeout(timeOut);
        }
    });

    // A self executing named function expression:
    (function autoAdvance(){
        // Simulating a click on the next arrow.
        timeOut = setTimeout(autoAdvance,2000);
        $('.slider_rightlink').trigger('click',[true]);
    })();

},2000);}

);

可能有一个 setTimeout jQuery 函数,但这会起作用。

$(window).load(function(){setTimeout(function(){

    // The window.load event guarantees that all the images are loaded before the auto-advance begins.
    var timeOut = null;

    $('#slider_navigator .arrow, #slider_navigator .dot').click(function(e,simulated){
        // The simulated parameter is set by the trigger method.
        if(!simulated){
            // A real click occured. Cancel the auto advance animation.
            clearTimeout(timeOut);
        }
    });

    // A self executing named function expression:
    (function autoAdvance(){
        // Simulating a click on the next arrow.
        timeOut = setTimeout(autoAdvance,2000);
        $('.slider_rightlink').trigger('click',[true]);
    })();

},2000);}

);

There's probably a setTimeout jQuery function, but this will work.

再见回来 2024-12-14 17:05:24

不要让它自动执行函数:

function autoAdvance(){
    // Simulating a click on the next arrow.
    timeOut = setTimeout(autoAdvance,2000);
    $('.slider_rightlink').trigger('click',[true]);
};
timeOut = setTimeout(autoAdvance,2000);

do not make it self executing function:

function autoAdvance(){
    // Simulating a click on the next arrow.
    timeOut = setTimeout(autoAdvance,2000);
    $('.slider_rightlink').trigger('click',[true]);
};
timeOut = setTimeout(autoAdvance,2000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文