手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >用jquery实现等比例缩放图片效果插件
用jquery实现等比例缩放图片效果插件
摘要:复制代码代码如下:jQuery.fn.autoZoomLoadImage=function(scaling,width,height,loa...

复制代码 代码如下:

jQuery.fn.autoZoomLoadImage = function(scaling, width, height, loadPic) {

if (loadPic == null) loadPic = "Loading.gif";

return this.each(function() {

var t = $(this);

var src = $(this).attr("src");

var img = new Image();

//alert("Loading")

img.src = src;

//自动缩放图片

var autoScaling = 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", "");

var loading = $("<img alt="加载中" title="图片加载中" src="" + loadPic + "" />");

t.hide();

t.after(loading);

$(img).load(function() {

autoScaling();

loading.remove();

t.attr("src", this.src);

t.show();

//alert("finally!")

});

});

}

【用jquery实现等比例缩放图片效果插件】相关文章:

jQuery实现表格行上下移动和置顶效果

JQuery分屏指示器图片轮换效果实例

jquery实现弹出层效果实例

jQuery实现文本展开收缩特效

jQuery实现返回顶部效果的方法

onmousewheel event 缩放图片效果

js兼容火狐显示上传图片预览效果的方法

使用node+vue.js实现SPA应用

jQuery插件Slider Revolution实现响应动画滑动图片切换效果

jQuery实现转动随机数抽奖效果的方法

精品推荐
分类导航