2011-12-27 78 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 
    } 
});