JQuery 圖片延遲加載并等比縮放插件
更新時(shí)間:2009年11月09日 00:50:43 作者:
圖片延遲加載并等比縮放,一個(gè)簡(jiǎn)單的JQuery插件。 需要的朋友可以參考下。
最近在學(xué)習(xí)JS的OOP所以寫了這么個(gè)東西
使用方法:
$(".viewArea img").zoom({height:74,width:103});
效果演示:
http://demo.jb51.net/html/jquery_img/jquery_img.htm
代碼:
(function($){
$.fn.zoom = function(settings){
//一些默認(rèn)配置;
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);
//預(yù)加載
var preLoad = function($this){
var img = new Image();
img.src = $this.src;
if (img.complete) {
processImg.call($this);
return;
}
//$this.src = loadding.src;//會(huì)導(dǎo)致獲取錯(cuò)誤的尺寸
img.onload = function(){
//$this.src = this.src; //會(huì)導(dǎo)致獲取錯(cuò)誤的尺寸
processImg.call($this);
img.onload=function(){};
}
}
//計(jì)算圖片尺寸;
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.jb51.net/html/jquery_img/jquery_img.htm
代碼:
復(fù)制代碼 代碼如下:
(function($){
$.fn.zoom = function(settings){
//一些默認(rèn)配置;
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);
//預(yù)加載
var preLoad = function($this){
var img = new Image();
img.src = $this.src;
if (img.complete) {
processImg.call($this);
return;
}
//$this.src = loadding.src;//會(huì)導(dǎo)致獲取錯(cuò)誤的尺寸
img.onload = function(){
//$this.src = this.src; //會(huì)導(dǎo)致獲取錯(cuò)誤的尺寸
processImg.call($this);
img.onload=function(){};
}
}
//計(jì)算圖片尺寸;
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);
效果是這樣的:

您可能感興趣的文章:
- jQuery實(shí)現(xiàn)等比例縮放大圖片讓大圖片自適應(yīng)頁(yè)面布局
- jquery 圖片預(yù)加載 自動(dòng)等比例縮放插件
- 基于JQuery實(shí)現(xiàn)的圖片自動(dòng)進(jìn)行縮放和裁剪處理
- jquery 圖片縮放拖動(dòng)的簡(jiǎn)單實(shí)例
- jquery實(shí)現(xiàn)圖片按比例縮放示例
- 基于jquery實(shí)現(xiàn)圖片相關(guān)操作(重繪、獲取尺寸、調(diào)整大小、縮放)
- jQuery實(shí)現(xiàn)的鼠標(biāo)滾輪控制圖片縮放功能實(shí)例
- jQuery圖片縮放插件smartZoom使用實(shí)例詳解
- jQuery圖片預(yù)加載 等比縮放實(shí)現(xiàn)代碼
- 基于jquery的防止大圖片撐破頁(yè)面的實(shí)現(xiàn)代碼(立即縮放)
- jQuery實(shí)現(xiàn)的移動(dòng)端圖片縮放功能組件示例
相關(guān)文章
jQuery插件Echarts實(shí)現(xiàn)的雙軸圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件Echarts實(shí)現(xiàn)的雙軸圖效果,結(jié)合完整實(shí)例形式分析了Echarts插件制作雙軸圖效果的操作步驟與相關(guān)實(shí)現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03動(dòng)態(tài)設(shè)置form表單的action屬性的值的簡(jiǎn)單方法
下面小編就為大家?guī)硪黄獎(jiǎng)討B(tài)設(shè)置form表單的action屬性的值的簡(jiǎn)單方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05jQuery動(dòng)態(tài)星級(jí)評(píng)分效果實(shí)現(xiàn)方法
這篇文章主要介紹了jQuery動(dòng)態(tài)星級(jí)評(píng)分效果實(shí)現(xiàn)方法,涉及jquery動(dòng)態(tài)操作頁(yè)面元素樣式的相關(guān)技巧,效果華麗大氣,是一款非常優(yōu)秀的特效源碼,需要的朋友可以參考下2015-08-08jQuery實(shí)現(xiàn)單擊按鈕遮罩彈出對(duì)話框(仿天貓的刪除對(duì)話框)
單擊刪除按鈕或者登陸按鈕后,彈出對(duì)話框問你是否刪除或者彈出一個(gè)登陸對(duì)話框,本文使用jquery來實(shí)現(xiàn)這種效果,需要的朋友可以參考下2014-04-04以WordPress為例講解jQuery美化頁(yè)面Title的方法
鼠標(biāo)移動(dòng)到超鏈接時(shí)顯示Title提示即是所謂Title美化的一般手段,這里我們就以WordPress為例講解jQuery美化頁(yè)面Title的方法,需要的朋友可以參考下2016-05-05