又一个图片自动缩小的JS代码

2022-10-18,,,

<script language="javascript"> 
<!-- 
var flag=false; 
function drawimage(imgd){ 
var image=new image(); 
image.src=imgd.src; 
if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= 180/110){ 
   if(image.width>180){
    imgd.width=180; 
    imgd.height=(image.height*110)/image.width; 
   }else{ 
    imgd.width=image.width;
    imgd.height=image.height; 
   } 
   /*imgd.alt="bigpic"  */
  } 
  else{ 
   if(image.height>110){
    imgd.height=110; 
    imgd.width=(image.width*110)/image.height; 
   }else{ 
    imgd.width=image.width;
    imgd.height=image.height; 
   } 
    /*imgd.alt="bigpic"  */ 
  } 
}
}
//--> 
</script>

图片使用的地方:
<img src="图片" border=0 width="180" height="110" onload="javascriptrawimage(this);">
width="180" height="110"  注意这里最好限定,如果不限定加载图时会成原大,然后再缩小,这个过程如果图大了很难看的.这里是宽度和高度,在前面的js里改,这里也作相应的改.

《又一个图片自动缩小的JS代码.doc》

下载本文的Word格式文档,以方便收藏与打印。