1. 论坛系统升级为Xenforo,欢迎大家测试!
    Dismiss Notice

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

Discussion in '前端开发' started by OUYANG, Nov 10, 2006.

  1. OUYANG

    OUYANG New Member

    Joined:
    Sep 6, 2005
    Messages:
    3,025
    Likes Received:
    5
    Code:
    <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

    Joined:
    Dec 17, 2005
    Messages:
    21
    Likes Received:
    0
  3. 老林

    老林 New Member

    Joined:
    Sep 6, 2005
    Messages:
    10,580
    Likes Received:
    36
    只要技术贴加分加分:)