我不懂JS,近日得到一段用鼠标滚轮控制图片伸缩的JS代码如下:
function bbimg(o)
{
var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
return false;

</script>
能不能控制图片的放大和缩小在一个特定的范围内进行?如要求图片的宽度在(100~600)之间进行伸缩。

解决方案 »

  1.   

    <SCRIPT language=JavaScript type=text/JavaScript>
     
    function ZoomImg(o) 
            { 
                var zoom = parseInt(o.style.zoom, 10) || 100; 
                zoom += event.wheelDelta / 12; 
                if(zoom > 0) 
                    o.style.zoom = zoom + '%'; 
                return false; 
            } 
    </SCRIPT>
    ----------------------------------------------------------------
     <img src="images/img.gif" onmousewheel="return ZoomImg(this)"  width="200" height="200">
      

  2.   

    在HEAD添加
    <script language="javascript">
    var count = 10;
    function resizeimg(oImage)
    {count = Counting(count);Resize(oImage,count);return false;}
    function Counting(newzoom)
    {if (event.wheelDelta >= 120)newzoom++;else if (event.wheelDelta <= -120)newzoom--;if (newzoom<2) newzoom=2; ////只允许缩小到20%
    if (newzoom>50) newzoom=50; ////只允许放大到500%
    return newzoom;}
    function Resize(oImage,newzoom){oImage.style.zoom = newzoom + '0%';count=newzoom;}
    </script>
    然后在<img src="">中加入onDblClick="return Resize(this,10);return false;"onmousewheel="return resizeimg(this)"