手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jquery预加载图片的方法
jquery预加载图片的方法
摘要:本文实例讲述了jquery预加载图片的方法。分享给大家供大家参考。具体如下:这段代码可以在页面打开前对图片进行预加载,这个函数非常有用,可以...

本文实例讲述了jquery预加载图片的方法。分享给大家供大家参考。具体如下:

这段代码可以在页面打开前对图片进行预加载,这个函数非常有用,可以给用户带来更好的体验。

function preloadImages(oImageList, callback) { if ( typeof (oImageList) == 'object' && typeof (callback) === "function") { var iCallbackAfter = oImageList.length; var iPreloadInterval = window.setInterval(function() { if (iCallbackAfter === 0) { window.clearInterval(iPreloadInterval); callback(); } }, 100); $.each(oImageList, function(iIndex, sImage) { oImageList[iIndex] = new Image(); oImageList[iIndex].onload = function(oResult) { iCallbackAfter--; }; oImageList[iIndex].onabort = function(oResult) { console.log(oResult); }; oImageList[iIndex].onerror = function(oResult) { console.log(oResult); }; if (!sImage.match('http://')) { sImage = sImage; } oImageList[iIndex].src = sImage; }); } }

希望本文所述对大家的jQuery程序设计有所帮助。

【jquery预加载图片的方法】相关文章:

js兼容火狐显示上传图片预览效果的方法

js比较日期大小的方法

jquery预加载图片的方法

jquery判断至少有一个checkbox被选中的方法

jQuery实现预加载图片的方法

JS/Jquery判断对象为空的方法

JQuery+CSS实现图片上放置按钮的方法

javascript先序遍历DOM树的方法

jQuery处理图片加载失败的常用方法

javascript实现行拖动的方法

精品推荐
分类导航