DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> JQuery 圖片延遲加載並等比縮放插件
JQuery 圖片延遲加載並等比縮放插件
編輯:JQuery特效代碼     
最近在學習JS的OOP所以寫了這麼個東西
使用方法:
$(".viewArea img").zoom({height:74,width:103});
效果演示:
http://demo.poluoluo.com/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);

效果是這樣的:
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved