jquery实现根据浏览器窗口大小自动缩放图片的方法
本文实例讲述了jquery实现根据浏览器窗口大小自动缩放图片的方法。分享给大家供大家参考。具体如下:
(function($){
$.fn.resizeimage=function(){
varimgLoad=function(url,callback){
varimg=newImage();
img.src=url;
if(img.complete){
callback(img.width,img.height);
}else{
img.onload=function(){
callback(img.width,img.height);
img.onload=null;
};
};
};
varoriginal={
width:$(window).width()
};
returnthis.each(function(i,dom){
varimage=$(this);
imgLoad(image.attr('src'),function(){
varimg={
width:image.width(),
height:image.height()
},percentage=1;
if(img.width<original.width){
percentage=1;
}else{
percentage=(original.width)/img.width;
}
image.width(img.w=img.width*percentage-30).height(img.h=img.height*percentage);
$(window).resize(function(){
varw=$(this).width();
percentage=w/img.width>1?1:w/img.width;
varnewWidth=img.width*percentage-30;
varnewHeight=img.height*percentage;
image.width(newWidth).height(newHeight);
});
});
});
};
})(jQuery);
希望本文所述对大家的jquery程序设计有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下