0

私が欲しい:

autoplay: false の場合、ウィンドウ サイズが width>900 で、

autoplay: true ウィンドウサイズが width<900 & width>701 かつ の場合、

autoplay: ウィンドウ サイズが width<701 の場合は false

jQuery flowlideshow を使用し、ウィンドウのサイズが変更されたときにこのコードを実行します

しかし、動作しません。

$(window).resize(function () {
var width = $(window).width();
if (width > 900) {
    $(function () {
        $(".slidetabs").tabs(".images > div", {
            // enable "cross-fading" effect
            effect: 'fade',
            fadeOutSpeed: "slow",
            // start from the beginning after the last tab
            rotate: true,
            showMultiple: 5
            // use the slideshow plugin. It accepts its own configuration
        }).slideshow({ **autoplay: false**, clickable: false });
    });
}
else if (width < 900 & width > 701) {
    $(function () {
        $(".slidetabs").tabs(".images > div", {
            // enable "cross-fading" effect
            effect: 'fade',
            fadeOutSpeed: "slow",
            // start from the beginning after the last tab
            rotate: true,
            showMultiple: 5
            // use the slideshow plugin. It accepts its own configuration
        }).slideshow({ **autoplay: true**, clickable: false });
    });
}
else (width < 701)
{
    $(function () {
        $(".slidetabs").tabs(".images > div", {
            // enable "cross-fading" effect
            effect: 'fade',
            fadeOutSpeed: "slow",
            // start from the beginning after the last tab
            rotate: true,
            showMultiple: 5
            // use the slideshow plugin. It accepts its own configuration
        }).slideshow({ **autoplay: false**, clickable: false });
    });
}    });
4

1 に答える 1

0

ウィンドウの onResize イベントは、ページの読み込み時に常に発生するとは限らないため、その場合、スライドショーは自動再生されません。ie9 でページの読み込み時に起動するようです。

また、このコードでは、ページのサイズが変更されるたびにスライドショーが再作成されます。これは、おそらくあなたが望むものでもありません。

ページの読み込み時にスライドショーをバインドしてから、スライドの動作を一時停止/再開するサイズ変更イベントをバインドすることをお勧めします。このような:

jQuery(function($) {
    // detect window size and init slideshow here
    $(window).on('resize', function () {
        // detect window size and pause or resume the slideshow
    });
});

使用しているスライドショーのドキュメントを見ないと、初期化後にスライドショーを変更する方法を正確に示すことはできませんが、上記の原則に従えば可能になるはずです。

(ちなみに、サイズ変更イベントが正しくトリガーされていることを確認するには、次のことができますconsole.log($(window).width())

さらにヘルプが必要な場合は、完全な例を含むFiddleを投稿し、使用しているスライドショー プラグインのドキュメントにリンクすることを検討してください。

于 2012-11-29T13:18:45.223 に答える