手机
当前位置:查字典教程网 >编程开发 >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实现用户打分评分特效

图片按比例缩放函数

js实现精美的图片跟随鼠标效果实例

纯javascript实现四方向文本无缝滚动效果

jQuery实现鼠标经过图片变亮其他变暗效果

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

jQuery实现给页面换肤的方法

jQuery实现不断闪烁文字的方法

精品推荐
分类导航