当窗口调整为776px及更小时,停止在bxslider上自动旋转

时间:2018-05-29 21:23:42

标签: javascript slider bxslider

当窗口大小为767px或更小时,如何使bxslider不自动旋转?这是我的代码

 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()
    });

1 个答案:

答案 0 :(得分:1)

保持简单:

$(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()
    });
  }
});

您可能需要添加一个事件来更新屏幕大小调整上的宽度变量。