[英]How to I preload images where it actually forces the images to load before continuing (html/javascript)?
我想預加載圖像,但是在繼續之前請確保已加載它們。 我怎樣才能做到這一點?
以下內容不起作用,因為它僅發送加載請求,而不會等到圖像加載完畢。 因此,可能在不久之后請求時未加載圖像。
jQuery.preloadImages = function () {
for (var i = 0; i < arguments.length; i++) {
jQuery("<img>").attr("src", arguments[i]);
}
}
$.preloadImages("img1.jpg","img2.jpg");
您是否查看過有關SO的討論:
jQuery.preloadImages = function () {
var image = new Image();
for (var i = 0; i < arguments.length; i++) {
image.src = arguments[i+1];
}
}
我還沒測試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.