How to specify different delays between slides in bxslider

我与影子孤独终老i 提交于 2020-01-14 06:48:27

问题


Ran across the following problem in bxslider- how can you apply different delays between slides in the auto show?


回答1:


I came up with the following solution which I will show here:

in the jquery.bxslider.js replace:

 el.startAuto = function(preventControlUpdate){
        // if an interval already exists, disregard call
        if(slider.interval) return;
        // create an interval
        slider.interval = setInterval(function(){
            slider.settings.autoDirection == 'next' ? el.goToNextSlide() : el.goToPrevSlide();
        }, slider.settings.pause);
        // if auto controls are displayed and preventControlUpdate is not true
        if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('stop');
    }

With

     /**EDITS: By CRB - techdude **/
    el.startAuto = function(preventControlUpdate){
        el.continueAuto();
    }

    el.continueAuto = function(){
        //get how long the current slide should stay
        var duration = slider.children.eq(parseInt(slider.active.index)).attr("duration");
        if(duration == ""){
            duration = slider.settings.pause;
        } else {
            duration = parseInt(duration);
        }
        console.log(duration);

        // create a timeout
        slider.timer = setTimeout(function(){
            slider.settings.autoDirection == 'next' ? el.goToNextSlide() : el.goToPrevSlide();
            el.continueAuto();
        }, duration);
        // if auto controls are displayed and preventControlUpdate is not true
        if (slider.settings.autoControls && preventControlUpdate != true) updateAutoControls('stop');

    }

    //*End Edits*/

Then to change the duration of a slide, simply give its li tag a duration attribute like this: where duration is the number of milliseconds for the slide to pause.

To set the default duration, simply use the pause: option in the settings:

$("element").bxSlider({
  auto:true,
  pause: 4000
};

Hope this helps. Maybe bx slider will even add it to a future version. :)




回答2:


What are the

  • you're using to pick this up? Any way you can put up a gist of it working?


    回答3:


    Perhaps this will help clarify: In principle, the way this works is I change the setInterval with a setTimeout so the interval can be changed each time.

    The key to getting multiple elements to work on a page is to not use the slider.timer object, but probably to use the el.timer object so the line would read something like,

     el.timer = setTimeout(function(){
            slider.settings.autoDirection == 'next' ? el.goToNextSlide() : el.goToPrevSlide();
            el.continueAuto();
        }, duration);
    

    Instead of

     slider.timer = setTimeout(function(){
            slider.settings.autoDirection == 'next' ? el.goToNextSlide() : el.goToPrevSlide();
            el.continueAuto();
        }, duration);
    

    I haven't tested it with multiple sliders, but let me know if this works. That is the principle anyway. The only problem with this, however, is that I believe that you would need to modify the el.pause method to use the el.timer as well, otherwise the slideshow can't be paused. I think that was the reason I did it the way I did. However, it was a long time ago.



    来源:https://stackoverflow.com/questions/17408118/how-to-specify-different-delays-between-slides-in-bxslider

  • 易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!