JQuery 图片延迟加载并等比缩放插件
作者:bea
最近在学习JS的OOP所以写了这么个东西 使用方法: $(".viewArea img").zoom({height:74,width:103}); 效果演示: http://demo./html/jquery_img/jquery_img.htm代码: 代码如下: (function($){ $.fn.zoom = function(settings){ //一些默认配置; settings = $.extend({ height:0, width:0,
最近在学习JS的OOP所以写了这么个东西
使用方法:
$(".viewArea img").zoom({height:74,width:103});
效果演示:
http://demo./html/jquery_img/jquery_img.htm代码:
代码如下:
(function($){
$.fn.zoom = function(settings){
//一些默认配置;
settings = $.extend({
height:0,
width:0,
loading:"lightbox-ico-loading.gif"
},settings);
var images = this;
$(images).hide();
var loadding = new Image();
loadding.className="loadding"
loadding.src = settings.loading;
$(images).after(loadding);
//预加载
var preLoad = function($this){
var img = new Image();
img.src = $this.src;
if (img.complete) {
processImg.call($this);
return;
}
//$this.src = loadding.src;//会导致获取错误的尺寸
img.onload = function(){
//$this.src = this.src; //会导致获取错误的尺寸
processImg.call($this);
img.onload=function(){};
}
}
//计算图片尺寸;
function processImg(){
//if(settings.height===0||settings.width ===0) return;
var m = this.height-settings.height;
var n = this.width - settings.width;
if(m>n)
this.height = this.height>settings.height ? settings.height :
this.height;
else
this.width = this.width >settings.width ? settings.width :
this.width;
$(this).next(".loadding").remove()
$(this).show();
}
return $(images).each(function(){
preLoad(this);
});
}
})(jQuery);
效果是这样的:
有用 | 无用
使用方法:
$(".viewArea img").zoom({height:74,width:103});
效果演示:
http://demo./html/jquery_img/jquery_img.htm代码:
代码如下:
(function($){
$.fn.zoom = function(settings){
//一些默认配置;
settings = $.extend({
height:0,
width:0,
loading:"lightbox-ico-loading.gif"
},settings);
var images = this;
$(images).hide();
var loadding = new Image();
loadding.className="loadding"
loadding.src = settings.loading;
$(images).after(loadding);
//预加载
var preLoad = function($this){
var img = new Image();
img.src = $this.src;
if (img.complete) {
processImg.call($this);
return;
}
//$this.src = loadding.src;//会导致获取错误的尺寸
img.onload = function(){
//$this.src = this.src; //会导致获取错误的尺寸
processImg.call($this);
img.onload=function(){};
}
}
//计算图片尺寸;
function processImg(){
//if(settings.height===0||settings.width ===0) return;
var m = this.height-settings.height;
var n = this.width - settings.width;
if(m>n)
this.height = this.height>settings.height ? settings.height :
this.height;
else
this.width = this.width >settings.width ? settings.width :
this.width;
$(this).next(".loadding").remove()
$(this).show();
}
return $(images).each(function(){
preLoad(this);
});
}
})(jQuery);
效果是这样的:
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- Javascript 解疑
- 不一样的文字闪烁 轮番闪烁
- JS旋转的彩色文字轮转特效
- 文字来回上下移动或跳动的代码
- jquery 输入框数字限制插件
- 通过隐藏option实现select的联动效果
- javascript实现的鼠标悬停时动态翻滚的导航条
- Js 实现表格隔行换色一例
- Javascript实现的CSS代码高亮显示
- Riot.js 快速的JavaScript单元测试框架
- asp.net HttpHandler实现图片防盗链
- 为javascript添加String.Format方法
- prototype 中文参数乱码解决方案
- javascript currying返回函数的函数
- jQuery 常见学习网站与参考书
- Javascript select下拉框操作常用方法
- 页面中js执行顺序
- js 鼠标拖动对象 可让任何div实现拖动效果
- Jquery作者John Resig自己封装的javascript 常用函数