20

我有一个我想从元素外部控制的 Flexislider。我试过这个:

var myslider = $('.slider').flexslider({
    animation: 'slide'
});

$('button').click(function () {
    myslider.flexAnimate(3)    //Function: Move slider - (target, pause) parameters
});

但这又回来了TypeError: Object [object Object] has no method 'flexAnimate'

然后我偶然发现了这个线程(https://github.com/woothemes/FlexSlider/issues/125),这表明这是正确的方法:

$('button').click(function () {
    myslider.flexslider(3)
});

但是我看不到如何指定动画的速度。我希望更改仅针对该事件是即时的。

我想我想知道如何从滑块元素外部访问文档中提到的滑块 API

slider                        //Object: The slider element itself
slider.container              //Object: The ul.slides within the slider
slider.slides                 //Object: The slides of the slider
slider.count                  //Int: The total number of slides in the slider
slider.currentSlide           //Int: The slide currently being shown
slider.animatingTo            //Int: Useful in .before(), the slide currently animating to
slider.animating              //Boolean: is slider animating?
slider.atEnd                  //Boolean: is the slider at either end?
slider.manualPause            //Boolean: force slider to stay paused during pauseOnHover event
slider.controlNav             //Object: The slider controlNav
slider.directionNav           //Object: The slider directionNav
slider.controlsContainer      //Object: The controlsContainer element of the slider
slider.manualControls         //Object: The manualControls element of the slider
slider.flexAnimate(target)    //Function: Move slider - (target, pause) parameters
slider.pause()                //Function: Pause slider slideshow interval
slider.resume()               //Function: Resume slider slideshow interval
slider.canAdvance(target)     //Function: returns boolean if slider can advance - (target) parameter
slider.getTarget(dir)         //Function: get target given a direction - "next" or "prev" parameter
4

6 回答 6

43

您可以像这样访问滑块对象:

var exampleSlider = $('#slider').data('flexslider');
// now you can access all the methods for example flexAnimate
exampleSlider.flexAnimate(..);

如上所述,您可以在https://github.com/woothemes/FlexSlider的 API 描述中找到它(源代码行:https ://github.com/woothemes/FlexSlider/blob/master/jquery.flexslider.js# L674 )

于 2012-10-17T11:17:50.040 回答
14

使用最新 (2.1) 版本的 Flexslider,您可以像这样使用外部 API:

$('button').click(function () {
    $('.slider').flexslider(3);
});

有关 API 的完整详细信息,请参见https://github.com/woothemes/FlexSlider#updates

于 2012-08-09T15:52:50.723 回答
3

这个对我有用:

    $('#slider').flexslider({
        animation: "slide",
        controlNav: false,
        animationLoop: false,
        slideshow: false,
        start: function(){
            $('#sliderNext').on('click', function(e){
                $('.flex-next').trigger('click');
            });
            $('#sliderPrev').on('click', function(e){
                $('.flex-prev').trigger('click');
            });
        }
    });
于 2014-04-17T19:26:03.297 回答
2

没有人回答主要问题:如何在没有动画的特定幻灯片上在灯箱中启动 flexslider,但随后在幻灯片之间有动画。我已经解决了这样的问题:

在打开灯箱(使用灯箱回调)之前,我将 flexslider 的动画速度设置为 0:

self.$slider.data('flexslider').vars.animationSpeed = 0;

打开灯箱(使用灯箱回调)后,我更改了 flexslider 索引并返回动画速度的先前值:

self.$slider.flexslider(this.index);
self.$slider.data('flexslider').vars.animationSpeed = 600; 
于 2014-10-31T00:04:10.437 回答
1

您可以先尝试设置滑块对象:

$slider = $('.slideshow').flexslider();

然后使用 flexslider 的公共方法:

$slider.data('flexslider').pause();
$slider.data('flexslider').play();
于 2017-06-07T07:19:49.203 回答
0
var myslider = ('.flexslider').flexslider({
   animation: 'slide',
   animationLoop: false
});
myslider.flexslider(3);

那对我有用。虽然我以不同的格式使用它。

var img = $('<span/>');
img.attr('onclick','myslider.flexslider('+ id + ');');

我有很多幻灯片要从数据库加载。

于 2015-10-07T13:30:20.937 回答