2

I am currently building a site which utilises multiple flexsliders. The concept is that when the user clicks a specific button, it shows a flexslider with featured content relevant to the button pressed, which is all pretty simple stuff.

The problem i am having is at the moment, the flexsliders are firing on the click of a button, however whenever a user clicks on a different button, the slider is not reset.

I want to try and make the slider reset to slide 0 on each button click. I have tried using .stop() and some of the callback features within the plugin, but i have had no luck as of yet. Was wondering if anybody else had ever faced this before? (and won..)

the code in the footer.php is pretty standard issue at the moment:

    $('.button').click(function() {
    $('.flexslider').flexslider({ 
        controlNav: true,
        directionNav: false,
        slideToStart: 0,  
        pauseOnHover: true,  
    });
});
4

3 回答 3

3

我知道这个问题发布已经很久了,但它可能会对某人有所帮助。

我实际上面临同样的问题。经过一番摸索后,我设法使用以下代码使其工作:

// Catch the flexslider context
var slider = $(".flexslider").data("flexslider");

// Unset the animating flag so we can move back to the first slide quickly      
slider.animating = false;

// Move to the first slide and stop the slideshow there
slider.flexAnimate(0, true, true);

如果您想在第一张幻灯片返回,但不希望动画停止,只需将最后一行替换为slider.flexAnimate(0);

我相信该slider.stop()方法不会取消设置animating标志。在我看来应该是,因为这个标志在flexAnimate()函数中用于检查是否实际滑动。如果标志设置为false,则flexAnimate()函数将突然返回。

于 2014-08-15T23:47:19.650 回答
0

在 flexslider 的第 1056 行使用新的 api,例如 ' startAt: 0,
//Integer: 滑块应该开始的幻灯片。数组表示法(0 = 第一张幻灯片)'

于 2014-05-14T09:01:52.823 回答
0

认为答案可能在于启动回调函数。尝试这样的事情(未经测试)

$('.button').click(function() {
   $('.flexslider').flexslider({ 
        controlNav: true,
        directionNav: false,
        slideToStart: 0,  
        pauseOnHover: true,
        start: function(slider) {
            if (slider.currentSlide != 0) {
                slider.flexAnimate(0)//move the slider to the first slide (Unless the slider is also already on the first slide);
            }
        }
   });
});
于 2012-04-16T17:27:23.157 回答