如果在页面对图片进行放缩,使图片适应指定的大小。假设我需要显示图片的地方大小为:(100,100)
如果对其他的图片进行放缩,让它适应这个显示区域。请给一段展示代码,谢谢。

解决方案 »

  1.   

    function DrawImage(ImgD,iwidth,iheight){
        //参数(图片,允许的宽度,允许的高度)
        var image=new Image();
        image.src=ImgD.src;
        if(image.width>0 && image.height>0){
        flag=true;
        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;
            }
        }
      

  2.   

    <a href="/business/changePhoto.jsp" target="mainFrame">
        <img src="../images/photo/touxiang.jpg"  alt="更换头像">
    </a>
    这个是我的程序,该如何调用呢。
      

  3.   

    <img onload=\"DrawImage(this,100,100);\" src="../images/photo/touxiang.jpg" alt="更换头像">
      

  4.   

    img{ width:100%}自动就根据外层的宽度来缩放了 缺点是 高度不能保证正好填满 顶下一楼