jQuery制作图片的等比例缩放
2013-08-22 14:13
344 查看
1资料的排版
2.html代码
3.css代码
4.js代码
2.html代码
<body> <div class="BB"><img src="dw.jpg" alt="动物" onload="setPic($(this))"/></div> <div class="BB"><img src="dw1.jpg" alt="动物" onload="setPic($(this))"/></div> <div class="BB"><img src="yy.jpg" alt="人" onload="setPic($(this))" /></div> </body>
3.css代码
<style type="text/css"> .BB{ width:100px; height:80px; border:1px solid red; overflow:hidden; margin-top:10px; float:left; margin-left:10px; text-align:center; line-height:100px; position:relative;} img{position:relative;} </style>
4.js代码
<script src="jquery-1.7.2.min.js" type="text/javascript"></script> <script type="text/javascript"> var BNImg = { iconW: 100, iconH: 80, getOriginPicWandH: function (imgObj) { return { width: imgObj.width(), height: imgObj.heght() }; }, setPicWandH: function (imgObj) { var originW = imgObj.width(); var originH = imgObj.height(); var maxWorH = originW >= originH ? { w: originW} : { h: originH }; var originRate = originW / originH; if (maxWorH.w) { imgObj.width(BNImg.iconW); var newH = BNImg.iconW / originRate imgObj.height(newH); var top = (BNImg.iconH - newH) / 2; imgObj.css("top",top+"px"); } else if (maxWorH.h) { imgObj.height(BNImg.iconH); imgObj.width(originRate * BNImg.iconH); } } }; function setPic(obj) { BNImg.setPicWandH(obj); }
相关文章推荐
- jQuery-图片预加载+等比例缩放
- jQuery-图片预加载 等比例缩放
- js 小小jquery等比例缩放图片效果
- jquery 等比例缩放图片插件
- 用 jQuery实现图片等比例缩放大小
- 使用jquery实现图片等比例缩放
- jQuery实现等比例缩放大图片
- jQuery实现按比例缩放图片
- jQuery实现按比例缩放图片
- 使用jquery按比例缩放图片
- jQuery插件——图片按比例自适应缩放
- jQuery-图片预加载+等比例缩放+图片在容器中上下左右居中!
- jquery图片预加载+自动等比例缩放插件
- jQuery实现等比例缩放大图片让大图片自适应页面布局
- jQuery实现按比例缩放图片的方法
- 【js与jquery】js控制图片显示大小(图片等比例缩放)
- jQuery实现等比例缩放大图片让大图片自适应页面布局
- jQuery实现等比例缩放大图片