手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >Jquery动态进行图片缩略的原理及实现
Jquery动态进行图片缩略的原理及实现
摘要:复制代码代码如下://页面加载完执行resizeImage()函数$(document).ready(resizeImage());func...

复制代码 代码如下:

//页面加载完执行resizeImage()函数

$(document).ready(resizeImage());

function resizeImage(){

$(".pic a img").each(function(){

//加载图片至内存,完成后执行

$(this).load(function(){

//获得原始图片高宽

var imgWidth = $(this).width();

var imgHeight = $(this).height();

//获得图片所在Div高宽

var boxWidth=$('.pic').width();

var boxHeight=$('.pic').height();

//比较imgBox的长宽比与img的长宽比大小

if((boxWidth/boxHeight)>=(imgWidth/imgHeight))

{

//重新设置img的width和height

$(this).width((boxHeight*imgWidth)/imgHeight);

$(this).height(boxHeight);

//让图片居中显示

var margin=(boxWidth-$(this).width())/2;

$(this).css("margin-left",margin);

}

else

{

//重新设置img的width和height

$(this).width(boxWidth);

$(this).height((boxWidth*imgHeight)/imgWidth);

//让图片居中显示

var margin=(boxHeight-$(this).height())/2;

$(this).css("margin-top",margin);

}

});

})

}

【Jquery动态进行图片缩略的原理及实现】相关文章:

jQuery实现首页图片淡入淡出效果的方法

Jquery实现动态切换图片的方法

javascript动态创建表格及添加数据实例详解

JS动画效果打开、关闭层的实现方法

javascript瀑布流式图片懒加载实例解析与优化

JQuery+CSS实现图片上放置按钮的方法

JQuery中节点遍历方法实例

JavaScript 预解析的原理及实现

jQuery插件expander实现图片翻转特效

Jquery使用css方法改变样式实例

精品推荐
分类导航