简体   繁体   English

jQuery Cycle2在悬停时反转

[英]jQuery Cycle2 reverse on hover

So I'm trying to create a carousel using the Cycle2 plugin. 因此,我尝试使用Cycle2插件创建轮播。 The difference to this one is that rather than just cycling back and forth when clicking on the next and previous button, it will also begin to cycle back and forth when hovering over the buttons. 与此不同的是,它不仅在单击下一个和上一个按钮时来回循环,而且在将鼠标悬停在按钮上时也将开始来回循环。

I'm able to create this behaviour for the next button with the following code which pauses the carousel and resumes it on the next button hover. 我可以使用以下代码为下一个按钮创建此行为,该代码会暂停轮播,并在下一个按钮悬停时恢复它。

$('.cycle-slideshow').cycle('pause');

$('#next').hover(function () {
    //mouse enter - Resume the slideshow
    $('.cycle-slideshow').cycle('resume');
}, function () {
    //mouse leave - Pause the slideshow
    $('.cycle-slideshow').cycle('pause');
});

I'm unable to figure out how to reverse the direction of the slideshow on the previous button hover. 我无法弄清楚如何反转上一个按钮悬停时的幻灯片显示方向。 Any ideas? 有任何想法吗?

Any input is greatly appreciated. 任何输入,不胜感激。 Thanks in advance. 提前致谢。

Assuming .cycle('prev') does not unpause the carousel. 假设.cycle('prev')不会取消转盘的暂停。 If it does you will need to pause it again after every .prev call and on the mouse leave function. 如果是这样,您将需要在每个.prev调用之后以及使用鼠标离开功能时再次将其暂停。

Try something like: 尝试类似:

var intervalVar;

$('#prev').hover(function () {
    //mouse enter - Resume the slideshow
    intervalVar = setInterval(function(){
        $('.cycle-slideshow').cycle('prev');
    },1000);
}, function () {
    //mouse leave - Pause the slideshow
    clearInterval(intervalVar);
});

This assumes that you cycle every 1 second.. You would change the 1000 to match however many milliseconds your carousel is set to transition. 假设您每隔1秒钟循环一次。您可以更改1000以匹配轮播设置为过渡的毫秒数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM