2013-12-20 88 views
0

我構建了一個函數,用於等待圖像加載,然後執行其他一些函數。在Fierfox中,它始終在Chrome中運行,有時無法運行。看起來,它並沒有繼續。什麼部分是壞的?我想是因爲加載圖像負載的功能不會被觸發:jquery - 加載函數在Chrome中無法正常工作

jQuery的

$("#myImages").load(function() { 
    var a = $("#visual").find('img').width(); 
    var b = $("#visual").find('img').height(); 
    var c = (a - 0.6 * a); 
    $("#box").css("height", b).css("width", (500 - c)); 
    $("#loading_screen").fadeOut(); 
    setTimeout(startAnimation, 800); 
}).attr('src', 'big_image.png'); 
+1

你在使用的document.ready它? – Johan

+0

我正在用js iffi加載它在身體的末端 – user2952265

+0

如果你可以放一個小提琴(http://jsfiddle.net/) – Johan

回答

0

包住整個事情在上功能齊全,像這樣...

$(document).ready(function() { 
$("#myImages").load(function() { 
    var a = $("#visual").find('img').width(); 
    var b = $("#visual").find('img').height(); 
    var c = (a - 0.6 * a); 
    $("#box").css("height", b).css("width", (500 - c)); 
    $("#loading_screen").fadeOut(); 
    setTimeout(startAnimation, 800); 
}).attr('src', 'big_image.png'); 
}); 

這樣在頁面實際準備好之前,函數不會嘗試運行。

+0

我這樣做了,但它確實沒有修復錯誤 – user2952265

0

試試這個:

$(window).bind('load', function(){ 
    //Page loaded 
}); 
相關問題