用jquery实现等比例缩放图片效果插件
2023-06-13 09:14:23 时间
jQuery.fn.autoZoomLoadImage=function(scaling,width,height,loadPic){
if(loadPic==null)loadPic="Loading.gif";
returnthis.each(function(){
vart=$(this);
varsrc=$(this).attr("src");
varimg=newImage();
//alert("Loading")
img.src=src;
//自动缩放图片
varautoScaling=function(){
if(scaling){
if(img.width>0&&img.height>0){
if(img.width/img.height>=width/height){
if(img.width>width){
t.width(width);
t.height((img.height*width)/img.width);
}
else{
t.width(img.width);
t.height(img.height);
}
}
else{
if(img.height>height){
t.height(height);
t.width((img.width*height)/img.height);
}
else{
t.width(img.width);
t.height(img.height);
}
}
}
}
}
//处理ff下会自动读取缓存图片
if(img.complete){
//alert("getToCache!");
autoScaling();
return;
}
$(this).attr("src","");
varloading=$("<imgalt=\"加载中\"title=\"图片加载中\"src=\""+loadPic+"\"/>");
t.hide();
t.after(loading);
$(img).load(function(){
autoScaling();
loading.remove();
t.attr("src",this.src);
t.show();
//alert("finally!")
});
});
}
相关文章
- jQuery 工具栏提示插件:qTip
- jQuery Google Charts—-一个封装google chart api的jquery插件详解编程语言
- JQuery上传插件Uploadify API详解编程语言
- jquery插件实现瀑布流详解编程语言
- jquery简单图片导航插件jquery.imgNav.js
- 一步一步制作jquery插件Tabs实现过程
- 小试JQuery的AutoComplete插件
- 基于jquery的lazyloader插件实现图片的延迟加载[简单使用]
- jquery图片上传按比例预览插件集合
- 50款非常棒的jQuery插件分享
- 推荐17个优美新鲜的jQuery的工具提示插件
- 11个用于提高排版水平的基于jquery的文字效果插件
- JQuery实现简单时尚快捷的气泡提示插件
- jQuery学习笔记(3)--用jquery(插件)实现多选项卡功能
- jQuery插件的写法分享
- 模拟电子签章盖章效果的jQuery插件源码
- jquery网页元素拖拽插件效果及实现
- js实现幻灯片效果(基于jquery插件)
- jquery中插件实现自动添加用户的具体代码
- jquery页面滚动到底部自动加载插件集合
- 在浏览器中实现图片粘贴的jQuery插件--pasteimg使用指南