2011-12-27 81 views

回答

1

我看到了网站。这与bing发生的情况是一样的。这个怎么做 ?

在核心HTML代码中给出<img src="loading.gif" id="1"/>或任何你想要的元素。

当芯HTML完成后,</body>标记之前,使用JavaScript来改变

属性值(例如,“SRC” img元素的属性)。在关闭body标签之前,记住JavaScript需要写在HTML的末尾。浏览器将依次加载相应的内容。这可以用来实现基于优先级的HTML组件加载。

1

您可以通过使用JS控制页面上的所有元素的同步加载。例如:内容加载之后加载图像的策略是:

a)在您的html中,而不是在src属性中,在另一个属性中指定图像位置,例如'isrc'。

B)内,您的onload事件的回调(假设你正在使用jQuery):

var loadCounter = 0; 
$('img').each(function() { 
    if($(this).attr('isrc')) { 
    this.onload = function() { 
     loadCounter++; 
     if($('img[isrc]').length == loadCounter) { 
     // .. proceed to loading other stuff like flash etc.. 
     } 
    } 
    $(this).attr('src', $(this).attr('isrc')); // load the image 
    } 
});