图片宽度自适应,高度等比例变化的js

<img src="upload/20061124114040.JPG" alt="" name="img1" border="0" id="img1">
<script language="javascript">
var flag=false;
DrawImage(img1);
function DrawImage(ImgD){ 
   var image=new Image(); 
   image.src=ImgD.src; 
   if(image.width>0 && image.height>0){ 
     flag=true; 
     if(image.width>=700){ 
       ImgD.width=700; 
       ImgD.height=(image.height*700)/image.width; 
     }else{ 
       ImgD.width=image.width; 
       ImgD.height=image.height; 
     } 
   } 

</script>

另外加一段通过计算控制当前图片大小的js

<img src="654662.jpg" border=0 id="thisImg" onload="(this.width = this.width / 100 * 28) ; this.height = this.height / 100 * 28)">

这是当天图片大小的 28%

posted @ 2012-05-30 13:48  小女阿媚  阅读(995)  评论(0编辑  收藏  举报