2

http://jquery.malsup.com/cycle2/api/を使用しています。モバイル デバイスを検出すると、ウィンドウのサイズ変更イベントで cycle2 スライダーを破棄しようとしています。残念ながら、次の 2 つのエラーが返されます。

[cycle2] slideshow must be initialized before sending commands; "destroy" ignored

[cycle2] slideshow must be initialized before sending commands; "reinit" ignored

多分誰かが助けることができます、私は何が間違っていますか? コードは次のとおりです。

$(function() {


    var slider = $('.slider').cycle();

    condition = true;

        //destroy onload under condition
    if(condition){
        slider.cycle('destroy');        
    }   

        //destroy on resize 
    $(window).on('resize',function() {              

        condition = true; //Will be function to recondition let´s say it's true by now

        if(condition){

                slider.cycle('destroy');

        } else {            

                slider.cycle('reinit');             

        }

    });

});

ありがとうございました。

4

2 に答える 2

2

ここでスライダーを破壊しているようです:

if(condition){
    slider.cycle('destroy');        
}

あなたはそのようにすることができます:

$(function() {

    var $W = $(window),
        slider = $('.slider').cycle();

    $W.on('resize',function() {              

        if ($W.width() < 768) // width of device 
            slider.cycle('destroy');

    });

});
于 2014-01-28T14:47:37.213 に答える