最新消息: 新版网站上线了!!!

用jquery等比例控制图片宽高的具体实现

代码如下:

$(function() { 
$(".dvcontent img").each(function() { 
var maxwidth = 520; 
if ($(this).width() > maxwidth) { 
var oldwidth = $(this).width(); 
var oldheight = $(this).height(); 
var newheight = maxwidth/oldwidth*oldheight; 
$(this).css({width:maxwidth+"px",height:newheight+"px",cursor:"pointer"}); 
$(this).attr("title","点击查看原图"); 
$(this).click(function(){window.open($(this).attr("src"))}); 

}); 
}); 
 
 

转载请注明:谷谷点程序 » 用jquery等比例控制图片宽高的具体实现