资料来源:网络整理
时间:2023/2/14 0:38:03 共计:3646 浏览
/**
* -------------------------------------------------------------
* 图片加载完成事件
* -------------------------------------------------------------
* 必须的JS: jquery.1.4.js
* -------------------------------------------------------------
* imgcomplete(callback): 绑定图片加载完成事件
* callback(Function): 内容变化事件回调函数
* 回调函数: function(width, height)
* 回调参数: width=图片实际宽度, height=实际高度, this=图片
* -------------------------------------------------------------
* author: 赵卉华
* date: 2012-11-13
* -------------------------------------------------------------
*/
(function($) {
$.fn.imgcomplete = function(callback) {
return this.each(function() {
var self = this,
$this = $(this);
if (!$this.is("img")) {
return true;
}
var img = new Image();
img.src = $this.attr("src");
if (img.complete) { // 如果图片已经存在于浏览器缓存, 直接回调
callback.call(self, img.width, img.height);
} else {
img.onload = function () { // 经测试IE/FF都支持(测了IE8/FF10)
if (!img.complete) return;
callback.call(self, img.width, img.height);
}
}
return true;
});
};
})(jQuery);
————————————————

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。