.NEt专家博客!

【凌风雨寒】asp.net:图片按比例缩放,可输入参数设定初始大小

上一篇 / 下一篇  2008-07-22 13:56:15 / 个人分类:WEB开发

<scriptlanguage="javascript">//图片按比例缩放,可输入参数设定初始大小functionresizeimg(ImgD,iwidth,iheight) {varimage=newImage();
image.src=ImgD.src;if(image.width>0 && image.height>0){if(image.width/image.height>= iwidth/iheight){if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}else{if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
     ImgD.style.cursor="pointer";//改变鼠标指针     ImgD.onclick =function() {window.open(ImgD.src);}//点击打开大图片    if(navigator.userAgent.toLowerCase().indexOf("ie") > -1) {//判断浏览器,如果是IE      ImgD.title ="请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
      ImgD.onmousewheel =functionimg_zoom()//滚轮缩放      {
          varzoom = parseInt(this.style.zoom, 10) || 100;
          zoom +=event.wheelDelta / 12;
          if(zoom> 0) this.style.zoom = zoom +"%";
          returnfalse;
      }
     }else{//如果不是IE            ImgD.title ="点击图片可在新窗口打开";
         }
}
}</script>具体实现代码如下:<imgsrc="http://www.chenjiliang.com/Article/ArticleImage/100/2176/SideFilter9.jpg"onload="javascript.:resizeimg(this,100,200)">
 

TAG: 微软

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-05  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 67609
  • 日志数: 1924
  • 影音数: 7
  • 文件数: 1
  • 建立时间: 2008-01-04
  • 更新时间: 2008-12-05

RSS订阅

Open Toolbar