【问题标题】:Cycle2 for Bootstrap 3, destroying cycle on mobile, reinitialising on larger than mobileBootstrap 3 的 Cycle2,在移动设备上破坏循环,在比移动设备更大的设备上重新初始化
【发布时间】:2014-03-06 18:47:44
【问题描述】:

我有一个奇怪的。我有一个使用 cycle2 的幻灯片,效果很好。我在我的 HTML 中初始化它:

<div class="content-slide-show cycle-slideshow" data-slides=".slide" data-next=".cycle-slideshow .next-slide" data-previous=".cycle-slideshow .previous-slide">

我正在使用

留意 initialized 和 destroyed 事件调用
var contentslideShowElement = $('.content-slide-show');
contentslideShowElement.on( 'cycle-initialized', function() {
    contentSlideShowInitialized = true;
});
contentslideShowElement.on( 'cycle-destroyed', function() {
    contentSlideShowInitialized = false;
});

然后使用监视来调整窗口大小

$(window).resize(function(){
    destroyContentSlideShowForMobile();
});

function destroyContentSlideShowForMobile(){
    if( contentSlideShowInitialized && $(window).width() < 768 ){
        contentslideShowElement.cycle('destroy');
    }

   if( !contentSlideShowInitialized && $(window).width() > 768 ){
        contentslideShowElement.cycle();
    }
}

基本上,如果幻灯片是幻灯片,然后浏览器被调整到低于 768 的大小,它应该会破坏幻灯片(然后我的 CSS 需要中继出 contnet)。

另一种状态询问幻灯片是否已被破坏,并且浏览器的大小调整为 768 以上以重新初始化循环。

这两个事件似乎都在工作(因为在循环日志中说它在正确的时间出现[cycle2] cycle-destroyed 和 [cycle2] --c2 init--,但是当它重新初始化时它就不起作用了。

有什么想法吗?

【问题讨论】:

    标签: javascript jquery html responsive-design jquery-cycle2


    【解决方案1】:

    事实证明,在原始元素上使用 . cycle() 并不会传递 HTML data- 值,所以我不得不修改重新初始化

    contentslideShowElement.cycle({
        slides: '.slide',
        next: ".cycle-slideshow .next-slide",
        previous: ".cycle-slideshow .previous-slide"
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多