Jquery 确认所有图像都已加载到`$(窗口).load()`函数中,然后继续

Jquery 确认所有图像都已加载到`$(窗口).load()`函数中,然后继续,jquery,slideshow,document-ready,Jquery,Slideshow,Document Ready,我正在为幻灯片放映向页面添加大量大型图像,但我只想在页面的正常部分(包括图像)完全加载后才开始加载这些图像 为此,我将在$(窗口)中添加图像。load()函数: var slide_total = 20; $(window).load(function() { for (i = 2; i <= slide_total; i++) { content = '<li><img src="/images/header' + ((i <

我正在为幻灯片放映向页面添加大量大型图像,但我只想在页面的正常部分(包括图像)完全加载后才开始加载这些图像

为此,我将在
$(窗口)中添加图像。load()
函数:

var slide_total = 20;

$(window).load(function() {

    for (i = 2; i <= slide_total; i++)
    {
        content = '<li><img src="/images/header' + ((i < 10) ? '0' : '') + i + '.jpg" width="960" height="314"></li>';
        $("#slideshow li:last-child").after(content);
    }

    slide_interval = setInterval( "slideSwitch()", slide_duration );

});
var-slide\u总计=20;
$(窗口)。加载(函数(){
对于(i=2;i试试这个:

// get the total number of images inserted in the DOM
var imgCount = $('#slideshow img').length;

// initialize a counter which increments whenever an image finishes loading
var loadCounter = 0;

// bind to the images' load event
$("#slideshow li img").load(function() {

    // increment the load counter
    loadCounter++;

    // once the load counter equals the total number of images
    // set off the fancy stuff
    if(loadCounter == imgCount) {
        slide_interval = setInterval( "slideSwitch()", slide_duration );
    }
}).each(function() {

    // trigger the load event in case the image has been cached by the browser
    if(this.complete) $(this).trigger('load');
});

window.load肯定会在加载之前等待所有内容firing@Galen,我知道,但正如你所看到的,图像被添加到window.load中,所以它已经启动了。啊,是的,我误解了你的问题,只是想补充一下,我在我们的一个web应用程序中成功地使用了上述技术,这要求在部分o中的所有图像启动后,有一些东西启动f文档已完全加载。谢谢,但它似乎不起作用。在IE8和IE7中,幻灯片放映在图像仍在加载时开始。您确定jquery
load()
方法可以这样使用吗?@jeroen-是的,我非常确定:)您正在计算正确的图像吗?我的意思是,尝试提醒图像计数以确保其正确。