2013-04-25 106 views
0

問題 - 在運行時,我正在使用jquery更改/替換某些圖像的src屬性。這些圖像默認是隱藏的。我想在下載這些圖像並準備顯示時顯示這些圖像,因爲某些圖像也可能無法下載。已使用jquery加載支票圖像

  <img id="pic_1" width="153" height="160" border="0" 
       onmouseout="this.style.border='2px solid #FFFFFF';" 
        onmouseover="this.style.border='2px solid #4585E7';" 
             style="visibility: hidden;" 
             src="**to be replaced at run time**""> 

請讓我知道任何解決方案我該如何做到這一點。

+0

您可以在這裏得到更多這方面的想法:http://stackoverflow.com/questions/1977871/check-if-an-image-is-loaded-no-errors-in-javascript – 2013-04-25 10:37:10

回答

1
$('#imgId').load(function(){ 
alert('Image Loaded') 
}); 
0

此代碼將鉤住您在網站上獲得的每個圖片,並且類爲「預加載」。

$(function(){ 
    //Hide all pictures first (You could here work on some loading animations if you want) 
    $("img.preload").css("display", "none"); 

    //When the image is loaded, show it again 
    $("img.preload").load(function(){ 
     $(this).css("display", "block"); 
    }); 
});