JQuery 循环暂停

发布于 2024-10-01 09:44:15 字数 455 浏览 9 评论 0原文

我希望将幻灯片暂停大约 4 秒钟,并且在恢复之前不显示幻灯片。这可能吗?我尝试使用以下代码自己执行此操作,但它似乎不起作用。

$(document).ready(function () {
        $('#homeSlideshowWrapper').cycle({
            fx: 'fade',
            timeout: 4000,
            after: onBefore
        });

        function onBefore() {
            $('#homeSlideshowWrapper').cycle('pause')
            $('#homeSlideshowWrapper').delay(5000).cycle('resume')

        } });

谢谢卢克

·斯特拉顿

I wish to pause the slideshow for about 4 seconds with no slide displayed before resuming. Is this possible? I have tried to do this myself with the following code but it does not seem to work.

$(document).ready(function () {
        $('#homeSlideshowWrapper').cycle({
            fx: 'fade',
            timeout: 4000,
            after: onBefore
        });

        function onBefore() {
            $('#homeSlideshowWrapper').cycle('pause')
            $('#homeSlideshowWrapper').delay(5000).cycle('resume')

        } });

Thanks

Luke Stratton

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

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

发布评论

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

评论(2

你的背包 2024-10-08 09:44:15

首先,onbefore 函数中的两个命令都缺少分号。其次,您在 document.ready 内部声明了一个函数,它实际上不应该出现在任何函数中。第三,您应该使用 .css(display, 'none') 在暂停时隐藏幻灯片(如果这就是您在恢复之前不显示幻灯片的意思)。如果不去掉 hide() 和 show() 处的行结束)。试试这个:

$(document).ready(function () {
    var onBefore= function() {
        $('#homeSlideshowWrapper').cycle('pause').hide();
        $('#homeSlideshowWrapper').delay(5000).cycle('resume').show();
    };

    $('#homeSlideshowWrapper').cycle({
        fx: 'fade',
        timeout: 4000,
        after: onBefore
    });

});

这可能并不完美,但应该会好一点。

First of all, you are missing semicolons on both commands in the onbefore function. Second of all, you are declaring a function inside of the document.ready, where it really should not be in any function. Third is that you should use .css(display, 'none') to hide the slideshow while it's paused (if that's what you mean by no slide displayed before resuming. If not get rid of the hide() and show() at the line ends). Try this:

$(document).ready(function () {
    var onBefore= function() {
        $('#homeSlideshowWrapper').cycle('pause').hide();
        $('#homeSlideshowWrapper').delay(5000).cycle('resume').show();
    };

    $('#homeSlideshowWrapper').cycle({
        fx: 'fade',
        timeout: 4000,
        after: onBefore
    });

});

That may not be perfect, but should be a bit better.

雨巷深深 2024-10-08 09:44:15

可以用setTimeout来实现吗?

例如

function onBefore() {
    $('#homeSlideshowWrapper').cycle('pause');
    $('selector-for-active-slide').css('visibility', 'hidden'); // If you wish the slide to disappear, not sure what you mean by "no slide displayed before resuming"
    setTimeout(resumeSlideshow, 5000);
}
function resumeSlideshow() {
    $('#homeSlideshowWrapper').cycle('resume');
    $('selector-for-active-slide').css('visibility', 'visible');
}

Can you achieve this with setTimeout?

E.g.

function onBefore() {
    $('#homeSlideshowWrapper').cycle('pause');
    $('selector-for-active-slide').css('visibility', 'hidden'); // If you wish the slide to disappear, not sure what you mean by "no slide displayed before resuming"
    setTimeout(resumeSlideshow, 5000);
}
function resumeSlideshow() {
    $('#homeSlideshowWrapper').cycle('resume');
    $('selector-for-active-slide').css('visibility', 'visible');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文