Search code examples
javascriptsliderbxslider

Stop auto rotate on bxslider when window resized to 776px and smaller


How would I make the bxslider to not auto rotate when the window size is 767px or smaller? Here is my code

 var slider = $('.bxslider-wrapper').bxSlider({
        autoHover: true,
        tickerHover: true,
        controls: false,
        pause: options.auto != '' ? options.auto : 4000,
        pager: options.showControls ? options.showControls : false,
        auto: options.auto != '' ? true : false,
        infiniteLoop: options.continuous ? options.continuous : false,
        touchEnabled: isTouchableDevice()
    });

Solution

  • Keep it simple:

    $(document).ready( function () {
      var width = $(window).width(); // get width of viewport
      if(width > 776) {
        var slider = $('.bxslider-wrapper').bxSlider({
            autoHover: true,
            tickerHover: true,
            controls: false,
            pause: options.auto != '' ? options.auto : 4000,
            pager: options.showControls ? options.showControls : false,
            auto: false
            infiniteLoop: options.continuous ? options.continuous : false,
            touchEnabled: isTouchableDevice()
        });
      } else {
        var slider = $('.bxslider-wrapper').bxSlider({
            autoHover: true,
            tickerHover: true,
            controls: false,
            pause: options.auto != '' ? options.auto : 4000,
            pager: options.showControls ? options.showControls : false,
            auto: true
            infiniteLoop: options.continuous ? options.continuous : false,
            touchEnabled: isTouchableDevice()
        });
      }
    });
    

    You may want to add an event to update the width variable on screen resize.