function ZoomImg(imgURL,W,H){
       if(imgURL.readyState != 'complete'){
              setTimeout("ZoomImg(imgURL,W,H)",500);
              return;
       }
       
       var Img = new Image();
       Img.src = imgURL.src;
       if(Img.width > 0 && Img.height > 0)
       {
              if(Img.width / Img.height >= W / H){
                     if(Img.width > W){
                            Img.height = W * Img.height / Img.width;
                            Img.width = W;
                     }                     
              }else{
                     if(Img.height > H){
                            Img.width = H * Img.width / Img.height;
                            Img.height = H;
                     }
              }
              imgURL.width = Img.width;
              imgURL.height = Img.height;       }
}<img src="1122.gif" onload="ZoomImg(this,200,220)"/>
ie6 、7可以使用,firefox下不正常

解决方案 »

  1.   

    window.onload = function(){
        ImgW("ImgHead" ,80);
    };
    function ImgW(ImgID,Width){
        var obj = document.getElementById(ImgID);
        if(obj != null)
        {
            var w = obj.width;
            var h = obj.height;        if (w > Width){
                obj.width = Width;
                obj.height = h*Width/w;
            }
        }
    };
      

  2.   

    http://shundebk.cn/temp/5.htm参考
      

  3.   

    Img.height   
    你这样的写法只能在IE中使用
    FF下不能这么用请查看
    Ie和firefox的Js区别 
    地址:
    http://blog.csdn.net/chinmo/archive/2008/02/17/2100325.aspx