图片加载完成事件(jQuery插件)
2014-02-22 15:28
711 查看
/** * ------------------------------------------------------------- * 图片加载完成事件 * ------------------------------------------------------------- * 必须的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);
相关文章推荐
- 判断图片是否加载完成(jquery插件fe)
- jquery插件实现图片延迟加载 -- jquery.lazyload
- 基于jquery的lazy loader插件实现图片的延迟加载[简单使用]
- 延迟加载图片的 jQuery 插件:Lazy Load
- jquery插件 —— Lazy Load 延迟加载图片
- jQuery lazyLoad图片延迟加载插件的优化改造方法分享
- js或者jquery判断图片是否加载完成实现代码
- jquery.lazyload 插件实现图片延迟加载
- Lazy Load, 延迟加载图片的 jQuery 插件
- jQuery插件实现的加载图片和页面效果
- Lazy Load, 延迟加载图片的 jQuery 插件
- 分享10个jQuery图片加载插件和教程及其生成器
- jquery.lazyload 实现图片延迟加载jquery插件
- jquery插件实现图片延迟加载 -- jquery.lazyload
- 第一次自己写jquery图片延迟加载插件,不通用,但修改一下还是可以使用到很多页面上的
- 缓冲加载图片的 jQuery 插件 lazyload.js 使用方法详解
- jquery插件jquery.lazyload实现的图片延迟加载
- Lazy Load, 延迟加载图片的 jQuery 插件
- Lazy Load, 延迟加载图片的 jQuery 插件
- Lazy Load, 延迟加载图片的 jQuery 插件