[英]How to detect when all images are loaded and elements are rendered at their appropriate heights
[英]How to detect when all images are loaded from dynamic page load?
我正在將包含圖像的另一頁加載到div。 我想檢測何時從動態添加的頁面加載所有圖像。
$("#main").load('imagespage.php', function(){
alert("Page loaded");
});
當加載頁面時(而不是加載圖像時),以上內容會發出警報。 在加載圖像之前會觸發。 通常,此窗口onload應該可以工作,但是如果它的動態加載頁面不起作用。
$(window).load(function() {
alert("window is loaded including images");
});
正確的方法是什么?
您會收到警報(“頁面已加載”); 在獲取$ .load調用的結果之前執行該命令,因為默認情況下該調用設置為異步。 如果將行為更改為同步,則可以在獲取$ .load結果之后執行任何操作。
您可以在執行之前嘗試設置行為:
jQuery.ajaxSetup({async:false});
然后,您可以再次更改它:
jQuery.ajaxSetup({async:true});
它適用於$ .get和$ .post ,但我從未嘗試過$ .load
加載所有圖像后,這應該可以工作。
$(window).on("load", function() {
alert("window is loaded including images");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.