1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

javascript等比例缩放控制图片(转的)

本帖由 OUYANG2006-11-10 发布。版面名称:前端开发

  1. OUYANG

    OUYANG New Member

    注册:
    2005-09-06
    帖子:
    3,025
    赞:
    5
    代码:
    <script lauguage="javascript">
    function resizeimg(ImgD,iwidth,iheight) {
        var image=new Image();
        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(this.src);} //
     
  2. 夜鸣猪

    夜鸣猪 New Member

    注册:
    2005-12-17
    帖子:
    21
    赞:
    0
    有用吗
     
  3. 老林

    老林 New Member

    注册:
    2005-09-06
    帖子:
    10,580
    赞:
    36
    只要技术贴加分加分:)