<div id="demo1"> <img src="a.jpg" width="800" height="300" alt="图片"> </div>
$(function(){
var w = $("#demo1").width();//容器宽度
$("#demo1 img").each(function(){//如果有很多图片,我们可以使用each()遍历
var img_w = $(this).width();//图片宽度
var img_h = $(this).height();//图片高度
if(img_w>w){//如果图片宽度超出容器宽度--要撑破了
var height = (w*img_h)/img_w; //高度等比缩放
$(this).css({"width":w,"height":height});//设置缩放后的宽度和高度
}
});
}); 
- 本文标题: jQuery实现等比例缩放大图片让大图片自适应页面布局
- 文章分类:【JQuery/JavaScript】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.