由於你原來的問題不包括任何提及的jQuery,這裏是一個簡單的javascript解決方案:
您可以使用onload
處理程序圖像:
<span><span id="imagesLoaded">No</span> images Loaded</span>
<div id="bar5" class="mosaic-block cover3">
<div class="mosaic-overlay"><img onload="imageLoaded()" src="images/Seg1.png" /></div>
<a href="#" target="_blank" class="mosaic-backdrop">
<div class="details">
<h4>Mounted iMac And Desk Mod With Computer Components Built In</h4>
<p>via Desktopped</p>
</div>
</a>
</div>
和JavaScript:
var imageCount = 0;
function imageLoaded() {
++imageCount;
document.getElementById("imagesLoaded").innerHTML = imageCount;
}
使用jQuery,如果你只是想在頁面中的所有圖像都被通知你可以用這個:
$(window).load(function() {
// code here that runs when all images are loaded
});
如果你不想改變你的HTML包括onload
處理程序,並希望每個圖像加載時得到通知,你可以用jQuery做到這一點:
$(document).ready(function() {
var imageLoadCount = 0;
function updateLoadCount() {
$("#imagesLoaded").html(imageLoadCount);
}
$("img").each(function() {
// check if the image is already loaded
if (this.complete) {
++imageLoadCount;
} else {
// image not loaded yet, install an event handler to notify us when it does
$(this).load(function() {
++imageLoadCount;
updateLoadCount();
});
}
});
if (imageLoadCount) {
updateLoadCount();
}
});
是在頁面加載得到的圖像加載或更新? –