手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jquery实现图片按比例缩放示例
jquery实现图片按比例缩放示例
摘要:.thumbnail{overflow:hidden;width:400px;height:240px;}$(function(){/*图片...

<html> <title></title> <head></head> <style> .thumbnail{overflow:hidden;width:400px;height:240px;} </style> <script src="http://code.jquery.com/jquery-1.4.1.min.js"></script> <script language="javascript"> $(function(){ /* 图片不完全按比例自动缩小 by zwwooooo */ $('#content div.thumbnail img').each(function(){ var x = 400; //填入目标图片宽度 var y = 240; //填入目标图片高度 var w=$(this).width(), h=$(this).height();//获取图片宽度、高度 if (w > x) { //图片宽度大于目标宽度时 var w_original=w, h_original=h; h = h * (x / w); //根据目标宽度按比例算出高度 w = x; //宽度等于预定宽度 if (h < y) { //如果按比例缩小后的高度小于预定高度时 w = w_original * (y / h_original); //按目标高度重新计算宽度 h = y; //高度等于预定高度 } } $(this).attr({width:w,height:h}); }); }); </script> <body> <div id="content"> <div id="thumbnail" > <img id="web" src="./midle.png"/> </div> </div> </body> </html>

【jquery实现图片按比例缩放示例】相关文章:

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

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

原生js实现的贪吃蛇网页版游戏完整实例

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

图片按比例缩放函数

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

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

jQuery实现的多屏图像图层切换效果实例

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

jQuery实现自动滚动到页面顶端的方法

精品推荐
分类导航