Image Preload插件onComplete函数

时间:2012-08-23 13:42:16

标签: jquery image preload

我在jquery预加载功能方面遇到了一些问题,并想知道是否有人可以帮助我。我已经在jquery preload插件中添加了加载我网站的背景图片,但是我想创建一个onComplete函数,这样当它们加载图像时它就会启动后台shuffle函数。但我似乎无法做到这一点。如果你知道一个更好的方法,或者一种方法,那就非常感谢。

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

});

0 个答案:

没有答案
相关问题