1

jquery プリロード機能にいくつか問題があり、誰か助けてくれるかどうか疑問に思いました。サイトの背景画像を読み込むために jquery プリロード プラグインを追加しましたが、画像が読み込まれると背景シャッフル機能が開始されるように onComplete 関数を作成したいと考えています。しかし、私はこれを行うことができないようです。それを行うためのより良い方法、またはそれを行う方法を知っていれば、それは大きな感謝です.

$(document).ready(function () {

    $.fn.preload = function () {
        this.each(function () {
            $('<img/>')[0].src = this;
        });
    }

    $(['../images/background1.jpg', '../images/background2.jpg', '../images/background3.jpg', '../images/background4.jpg', '../images/background5.jpg', '../images/background6.jpg', '../images/background7.jpg']).preload();

    var images = new Array();
    images[1] = "../images/background-1.jpg",
images[2] = "../images/background-7.jpg",
images[3] = "../images/background-4.jpg",
images[4] = "../images/background-5.jpg",
images[5] = "../images/background-6.jpg",
images[6] = "../images/background-2.jpg",

    Array.prototype.shuffle = function () {
        var len = this.length;
        var i = len;
        while (i--) {
            var p = parseInt(Math.random() * len);
            var t = this[i];
            this[i] = this[p];
            this[p] = t;
        }
    };
    images.shuffle();
    // A little script for preloading all of the images

    // It's not necessary, but generally a good idea


    var index = 0;

    $.backstretch(images[index], { speed: 1000 });

    var slideshow = setInterval(function () {

        index = (index >= images.length - 1) ? 0 : index + 1;

        $.backstretch(images[index]);

    }, 5000);

});
4

0 に答える 0