标题: 图片自动缩小的js代码,用以防止图片撑破页面
ljjk5
元帅
Rank: 1


荣誉会员奖章
UID 46706
精华 1
积分 99426
帖子 49690
威望 554
金币 48489
热心 505
阅读权限 100
注册 2007-2-25
状态 离线
图片自动缩小的js代码,用以防止图片撑破页面

<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里改,这里也作相应的改.

图不会变形,只会按比列缩,放心

顶部
[广告] 免费域名(Free Subdomain) 免费空间(Free hosting) PR查询(Google Pagerank)



当前时区 GMT+8, 现在时间是 2008-10-13 05:30
信产部ICP备案:京ICP备05066424号 北京市公安局网监备案:1101050648号

Powered by Discuz! 5.5.0
清除 Cookies - 联系我们 - 网友俱乐部 - Archiver - WAP