0

私がjqueryで書いたこの関数は、プリロードするのに良い方法ですか?ありがとうございました

function loader(){

        imgTag('#check');

        function imgTag(whereToAppend){
            var image = 'image.jpg';

            $(whereToAppend).append('<img id="imgWrapper">');

            $('#imgWrapper').attr('src', image).hide().one('load',function(){
                $(this).fadeIn('slow');
            })
        }


    }
4

1 に答える 1

1

画像をプリロードするには、次のソリューションを使用することをお勧めします。

function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
}

// Usage:

preload([
    'img/imageName.jpg',
    'img/anotherOne.jpg',
    'img/blahblahblah.jpg'
]);

出典: jQuery による画像のプリロード

于 2012-04-22T18:09:05.783 に答える