0

首先,我对javascript知之甚少。我需要一个基本的预加载器来从我的网站加载一些重图像,这是我找到的脚本:

<div class="hidden">
            <script type="text/javascript">
                <!--//--><![CDATA[//><!--
                    var images = new Array()
                    function preload() {
                        for (i = 0; i < preload.arguments.length; i++) {
                            images[i] = new Image()
                            images[i].src = preload.arguments[i]
                        }
                    }
                    preload(
                        "img/artistes/01/01.jpg",
                        "img/artistes/01/02.jpg",
                        "img/artistes/01/03.png",
                        "img/artistes/01/04.jpg",
                        "img/artistes/01/05.jpg",
                        "img/artistes/01/06.png",
                        "img/artistes/01/07.jpg",
                        "img/artistes/01/08.jpg",
                        "img/artistes/01/09.jpg",
                        "img/artistes/01/10.jpg",
                        "img/artistes/01/11.jpg",
                        "img/artistes/01/12.jpg",
                        "img/artistes/01/13.jpg",
                        "img/artistes/01/14.jpg",
                        "img/artistes/01/15.png",
                        "img/artistes/01/16.jpg",
                        "img/artistes/01/thumbs/01.jpg",
                        "img/artistes/01/thumbs/02.jpg"
                    )
                //--><!]]>
            </script>
        </div>

我想知道它们是否是一种在所有这些图像都被加载后简单地删除这个 div 的方法?

谢谢你的帮助

4

1 回答 1

3

对于 jQuery,您可以在页面顶部使用此代码,

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

// Usage:

preload([
    "img/artistes/01/01.jpg",
    "img/artistes/01/02.jpg",             
    "img/artistes/01/03.png",   
    "img/artistes/01/04.jpg",    
    "img/artistes/01/05.jpg",
    "img/artistes/01/06.png",
    "img/artistes/01/07.jpg",
    "img/artistes/01/08.jpg",
    "img/artistes/01/09.jpg",
    "img/artistes/01/10.jpg",
    "img/artistes/01/11.jpg",
    "img/artistes/01/12.jpg",
    "img/artistes/01/13.jpg",
    "img/artistes/01/14.jpg",
    "img/artistes/01/15.png",
    "img/artistes/01/16.jpg",
    "img/artistes/01/thumbs/01.jpg",
    "img/artistes/01/thumbs/02.jpg"
]);

注意:你不需要隐藏或删除任何东西,这对任何人都是不可见的。

于 2013-06-17T12:41:31.537 回答