如何在播放期间反转 jQuery Cycle 幻灯片中显示的图片顺序?

发布于 2024-10-18 10:44:30 字数 250 浏览 8 评论 0原文

所以我的问题非常简单。假设我有一个带有“淡入淡出”过渡的幻灯片,总共有 10 张图片,并且我还有典型的下一张/上一张按钮。幻灯片自动从图像 1 循环到图像 10。如何让用户可以随时反转播放顺序?例如,在观看图像 6 时,用户单击“上一页”(或必要时单击新按钮),然后返回到图像 5 后,幻灯片继续播放图像 4、3、2...

这可能吗?我读到并尝试了 Cycle 中的“rev”选项,但我无法使其工作,实际上我不确定它的目的是我需要的。

谢谢您的任何想法!

So my question is pretty straight-forward. Say I have a slideshow running with 'fade' transitions with 10 pictures in total, and I have the typical next/prev buttons as well. The slideshow cycles automatically from image 1 to image 10. How can I make it possible for the user to reverse the playback order at any moment? For example, while watching image 6, the user clicks 'prev' (or a new button if necessary), and after going back to image 5, the slideshow continues with image 4, 3, 2...

Is this even possible? I read about and tried the 'rev' option in Cycle, but I couldn't make it work, and actually I'm not sure that its purpose is the one I need.

THank you for any ideas!

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

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

发布评论

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

评论(1

白日梦 2024-10-25 10:44:30

查看源代码,看起来 rev 选项仅适用于动画,不适用于淡入淡出。以下是确切的评论:

// causes animations to transition in reverse (for effects that support it such as scrollHorz/scrollVert/shuffle)

您可能正在寻找向后

// true to start slideshow at last slide and move backwards through the stack

当您想要颠倒顺序时,请尝试将其设置为 true。

编辑:可能有更好的方法来做到这一点。无论如何,这是一种方法。首先,向按钮添加一个调用某个函数的点击处理程序:

function toggleDirection(){
    // replace your_slide_div with whatever your div is named
    $('.your_slide_div').cycle("toggleDirection");
}

然后在循环插件 JS 文件中查找 handleArguments(cont, options, arg2) 函数。在 switch 语句中,添加一个案例:

case "toggleDirection":
        $(cont).data('cycle.opts').backwards = $(cont).data('cycle.opts').backwards ? false : true;
        if($(cont).data('cycle.opts').backwards)
            $(cont).data('cycle.opts').nextSlide = 
                $(cont).data('cycle.opts').nextSlide - 2 < 0 ? 
                $(cont).children().length - 1 : $(cont).data('cycle.opts').nextSlide - 2;
        else
            $(cont).data('cycle.opts').nextSlide = 
                $(cont).data('cycle.opts').nextSlide + 2 >= $(cont).children().length ? 
                0 : $(cont).data('cycle.opts').nextSlide + 2;
        return false;

编辑:此案例假设您正在滑动浏览所有图像。如果您使用slideExpr选项,那么这会导致问题。

请注意,这会切换方向,因此单击按钮两次会使其恢复正常,如果您只想反转方向,请将大小写更改为:

(cont).data('cycle.opts').backwards = true;

编辑:希望是最后一个。在插件 JS 文件中,搜索以下内容:

opts.nextSlide < opts.currSlide

将特定选择替换为:

opts.currSlide == els.length - 1

Looking at the source, it looks like the rev option is only for animations, which doesn't apply to fade. Here is the exact comment:

// causes animations to transition in reverse (for effects that support it such as scrollHorz/scrollVert/shuffle)

You may be looking for backwards:

// true to start slideshow at last slide and move backwards through the stack

Try setting that to true when you want to reverse the order.

EDIT: There is probably a better way to do this. In any case, here is one way. First, add a click handler to your button that calls some function:

function toggleDirection(){
    // replace your_slide_div with whatever your div is named
    $('.your_slide_div').cycle("toggleDirection");
}

Then in the cycle plugin JS file, look for the handleArguments(cont, options, arg2) function. In the switch statement, add a case:

case "toggleDirection":
        $(cont).data('cycle.opts').backwards = $(cont).data('cycle.opts').backwards ? false : true;
        if($(cont).data('cycle.opts').backwards)
            $(cont).data('cycle.opts').nextSlide = 
                $(cont).data('cycle.opts').nextSlide - 2 < 0 ? 
                $(cont).children().length - 1 : $(cont).data('cycle.opts').nextSlide - 2;
        else
            $(cont).data('cycle.opts').nextSlide = 
                $(cont).data('cycle.opts').nextSlide + 2 >= $(cont).children().length ? 
                0 : $(cont).data('cycle.opts').nextSlide + 2;
        return false;

EDIT: This case assumes that you are sliding through all your images. If you are using the slideExpr option, then this will cause problems.

Note that this toggles the direction, so clicking the button twice returns it to normal, if you only want it to reverse it, change the case to:

(cont).data('cycle.opts').backwards = true;

EDIT: Last one hopefully. In the plugin JS file, do a search for the following:

opts.nextSlide < opts.currSlide

Replace that specific selection with:

opts.currSlide == els.length - 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文