jQuery预文档就绪事件

Luk*_*dge 1 jquery image download

我有一个179个缩略图的列表,我试图将jQuery灯箱工具应用于无序的超链接列表.

我遇到的问题是,jQuery不会触发,直到图像完成下载,每个图像大约23K左右,所以自己,不是那么大,但作为一个组,这相当于大约4MB.

IE页面(客户端使用的主浏览器)在页面完全下载每个缩略图之前有5秒的延迟,然后允许jQuery触发.

我已经尝试将jQuery文档就绪事件放在各个地方但没有成功,并且只能通过display:none在应用.show()灯箱之后应用之前将ul上的css设置为隐藏使用来放置一个bandaid .

我希望有一种方法可以在下载所有内容之前激活jQuery脚本吗?

干杯

更新:我的代码是:

$(document).ready(function(){
    $("li.eventPhoto a").lightBox();
});
Run Code Online (Sandbox Code Playgroud)

但是这不适用于IE,直到所有图像都加载完毕.

Rik*_*ood 5

$(document).ready()将在DOM完成加载后立即执行(即,在所有图像完成下载之前,但只要您的页面的所有html都已完成加载).例如...

$(document).ready(function(){
    // do someting as soon as the document is ready, 
    // possibly before the images are loaded
}) ;
Run Code Online (Sandbox Code Playgroud)

如果你想在所有图像加载完毕后做一些事情,那么你需要使用onload事件,就像这样......

$(window).bind('load', function() {
    // Do something when the images have finished loading
});
Run Code Online (Sandbox Code Playgroud)

如果您现在想要立即执行脚本,在它出现在html文档中时,请不要使用任何"就绪"功能.那就做对了...

<script>
    // code that you want to execute as soon as the browsers finds this bit of your doc.
    // note that you won't be able to access the DOM as it may not all be present
</script>
Run Code Online (Sandbox Code Playgroud)