满意答案
goabe99167
2013.08.06
采纳率:56% 等级:12
已帮助:15789人
要使图片等比例缩小的话用js解决
<script language="JavaScript" type="text/javascript">
<!--
function DrawImage(ImgD,FitWidth,FitHeight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= FitWidth/FitHeight){
if(image.width>FitWidth){
ImgD.width=FitWidth;
ImgD.height=(image.height*FitWidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
} else{
if(image.height>FitHeight){
ImgD.height=FitHeight;
ImgD.width=(image.width*FitHeight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
//-->
</script>
然后插入图片的时候加上 οnlοad=javascript:DrawImage(this,550,600);
注:550为最大宽度即div宽度,600为最大高度即div高度,图片就在宽550px,高600px内等比例缩小.这两个数值可根据需要改变
即<img src="uploadfiles/123.gif" οnlοad=javascript:DrawImage(this,550,600); boder=0/>
00分享举报