JavaScript控制圖片加載完成后調(diào)用回調(diào)函數(shù)的方法
本文實例講述了JavaScript控制圖片加載完成后調(diào)用回調(diào)函數(shù)的方法。分享給大家供大家參考。具體分析如下:
這段代碼可以控制指定區(qū)域內(nèi)的圖片加載完成后執(zhí)行指定的回調(diào)函數(shù)。
/* do callback when images in $img_container (jQuery object) are loaded. Only works when ALL images in $img_container are newly inserted images and this function is called immediately after images are inserted into the target. */
var _imgs = $img_container.find('img'),
img_length = _imgs.length,
img_load_cntr = 0;
if (img_length) {//if the $img_container contains new images.
_imgs.on('load', function() {//then we avoid the callback until images are loaded
img_load_cntr++;
if (img_load_cntr == img_length) {
callback();
}
});
}
else { //otherwise just do the main callback action if there's no images in $img_container.
callback();
}
}
希望本文所述對大家的javascript程序設(shè)計有所幫助。
相關(guān)文章
js實現(xiàn)的頁面加載完畢之前l(fā)oading提示效果完整示例【附demo源碼下載】
這篇文章主要介紹了js實現(xiàn)的頁面加載完畢之前l(fā)oading提示效果,結(jié)合完整實例形式分析了js頁面加載時顯示loading效果的實現(xiàn)技巧,需要的朋友可以參考下2016-08-08BootStrap中Table隱藏后顯示問題的實現(xiàn)代碼
這篇文章主要介紹了BootStrap中Table隱藏后顯示問題的實現(xiàn)代碼,需要的朋友可以參考下2017-08-08基于VSCode調(diào)試網(wǎng)頁JavaScript代碼過程詳解
這篇文章主要介紹了基于VSCode調(diào)試網(wǎng)頁JavaScript代碼過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-07-07JavaScript使用Blob文件流下載txt、pdf、圖片等文件,自定義下載文件名
JavaScript使用Blob文件流下載txt、pdf、圖片等格式文件,同時自定義下載文件名,2023-08-08