2012-12-13 39 views
1

我使用這個代碼的圖像加載調用一個函數後,圖像加載,並且還出現圖像加載還調用函數

var height = 0; 
$("#right-layout-ul li img").on("load",function(){ 
    function_function();  
}); 

後,如果我刷新該函數的頁面調用函數不呼叫,因爲圖像已經加載...

有沒有什麼辦法來找到像加載或加載圖像的狀態?

我要調用一個函數圖像加載後,如果圖像加載還調用函數...

如何實現???請幫我

+0

嗨,老兄你不能使用 '$( 「#右佈局-UL李IMG」)上。( 「準備就緒」,函數(){ 創建my_function();} ) ;' –

+0

爲什麼不能使用? – rynhe

回答

3
var $images = $("#right-layout-ul li img") 
, imageCount = $images.length 
, counter = 0; 

// one instead of on, because it need only fire once per image 
$images.one("load",function(){ 

    // increment counter everytime an image finishes loading 
    counter++; 
    if (counter == imageCount) { 

     // do stuff when all have loaded 
     function_function(); 
    } 
}).each(function() { 
    if (this.complete) { 

     // manually trigger load event in 
     // event of a cache pull 
     $(this).trigger("load"); 
    } 
}); 
+0

謝謝!!!讓我檢查! – rynhe