如果在div中放一个图片,如何设置图片大小随着div的大小变化而变化

解决方案 »

  1.   

    不知道是不是这样的效果
    顺便在冒昧的说2句
    2分帖 不是很感兴趣的帖子  貌似别人就算会写也未必帮你写 就算别人不在乎分
    <script>function zoom(id){
      var obj= this
      this.element = document.getElementById(id)
      document.getElementById(id).onmousedown =function(e)
      {
        e = e || event
        var oo = obj.element
        oo.width  = oo.offsetWidth
        oo.height = oo.offsetHeight
        oo.cx = e.clientX
        oo.cy = e.clientY
           document.onmousemove=function(e)
            {
              e = e || event 
              var oo = obj.element
    document.getElementById("gg").setCapture();
    oo.style.width  = (oo.width + e.clientX - oo.cx)>0?(oo.width + e.clientX - oo.cx):0; 
    oo.style.height = (oo.height + e.clientY - oo.cy)>0?(oo.height + e.clientY - oo.cy):0;
    document.getElementById("s").style.width=document.getElementById("gg").offsetWidth-10
    document.getElementById("s").style.height=document.getElementById("gg").offsetHeight-10
            }
          document.onmouseup=function()
            {
              document.getElementById("gg").releaseCapture();
              document.onmousedown = null
              document.onmousemove = null
            }
      }
    }
    window.onload = function(){
    new zoom("gg")
    }
    </script>
    <body><div id="gg" style="width:150px; height:150px; background:#99FF00; cursor:nw-resize; border:1px solid #000000">
    <img id="s" src="http://img1.qq.com/news/pics/14176/14176497.jpg" style="width:140px; height:140px;">
    </div></body>