破程序搞得我浏览器都死掉了~~
到边不能拖动?if (x <= 0)
{
  x = 0;
}

解决方案 »

  1.   

    哈哈。。不是吧?
    我看这儿看挺好的呀。
    if (x <= 0)
    {
      x = 0;
    }
    你的x哪来的?
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> Document </TITLE>
    <style type="text/css">
    body{
    margin : 0px;
    background-color : #999999 ;
    }
    .DivMain {
    position : absolute ;
    text-align : center ;
    overflow : hidden ;
    }
    .DivMenu {
    position : absolute ;
    text-align : left ;
    overflow : hidden ;
    visibility : hidden ;
    }
    .ImgMain {
    position : absolute ;
    overflow : hidden ;
    border : 0px ;
    }
    .TBMain {
    background-color : #CCCCCC ;
    padding : 0px ;
    border : 0px ;
    z-index : 99 ;
    line-height : 18px ;
    }
    </style><SCRIPT LANGUAGE="JavaScript">
    <!-- var originalWidth;
    var originalHeight;
    var ObjDrag;function setInit(objImg) { originalWidth = objImg.width;
    originalHeight = objImg.height;
    fmImgZoom.Original.click();
    }function setOriginal() { var objImg;
    var objDivMain ;
    var intBodyWidth ;
    var intBodyHeight ; intBodyWidth = document.body.clientWidth ;
    intBodyHeight = document.body.clientHeight ; objImg = document.getElementById("imgMain") ;
    objDivMain = document.getElementById("divMain") ; objImg.style.left = 0 ;
    objImg.style.top = 0 ;
    objImg.style.width = originalWidth;
    objImg.style.height = originalHeight;
    objImg.style.zoom = 1 ; objDivMain.style.width = intBodyWidth ;
    objDivMain.style.height = intBodyHeight - 20 ; fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
    }function initImg(objCurrent) { var intBodyWidth ;
    var intBodyHeight ;
    var objTbMain ;
    var objDivMain ; intBodyWidth = document.body.clientWidth ;
    intBodyHeight = document.body.clientHeight ; objTbMain = document.getElementById("tbMain") ;
    objDivMain = document.getElementById("divMain") ; objTbMain.style.top = 0;
    objTbMain.style.height = 20;
    objTbMain.style.width = intBodyWidth;

    objDivMain.style.left = 0 ;
    objDivMain.style.height = intBodyHeight - 20 ;
    objDivMain.style.width = intBodyWidth ; initZoom(objCurrent);
    }function initZoom(obj){ var intObjWidth ;
    var intObjHeight ;
    var intDivHeight ;
    var intZoomRatio ;
    var objDivMain ;
    var objTbMain; objDivMain = document.getElementById("DivMain");
    objTbMain = document.getElementById("tbMain") ; intDivHeight = objDivMain.style.pixelHeight;
    intObjHeight = obj.style.pixelHeight;
    intZoomRatio = intDivHeight / intObjHeight; obj.style.zoom = intZoomRatio ;
    obj.style.top = 0;
    obj.style.left = 0; fnWritePos (obj.style.left,obj.style.top,obj.style.zoom) ;
    }function setFitScreen() { var objImg; objImg = document.getElementById("imgMain") ;
    initImg(objImg);
    }function fnMouseDown(obj) {
    ObjDrag=obj;
    ObjDrag.setCapture();
    ObjDrag.l=event.x-ObjDrag.style.pixelLeft;
    ObjDrag.t=event.y-ObjDrag.style.pixelTop;
    }function fnMouseMove() {
    if(ObjDrag!=null) {
    ObjDrag.style.left = event.x-ObjDrag.l;
    ObjDrag.style.top = event.y-ObjDrag.t;
    fnWritePos(ObjDrag.style.left,ObjDrag.style.top,ObjDrag.style.zoom);
    }
    }function fnMouseUp() {
    if(ObjDrag!=null) {
    ObjDrag.releaseCapture();
    ObjDrag=null;
    }
    }function fnZoomIn() { var objImg; objImg = document.getElementById("imgMain") ;
    objImg.style.zoom = parseFloat(objImg.style.zoom) + 0.01 ;
    fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
    }function fnZoomOut() {
    var objImg;
    objImg = document.getElementById("imgMain") ;
    if(objImg.style.zoom>0.01){
    objImg.style.zoom = parseFloat(objImg.style.zoom) - 0.01 ;
    fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
    }
    }function fnDivMouseDown() {
    if ( event.button == 2 && event.srcElement.id != "imgMain") {
    setOriginal();
    }
    }function fnWritePos(intLeft,intTop,intZoom) {
    var objbtnImgInfo;
    objbtnImgInfo = document.getElementById("btnImgInfo") ;
    objbtnImgInfo.innerText = " ImgLeft:" + intLeft + " ImgTop:" + intTop + " ImgZoom:" + intZoom ;
    }function setDisplay() { var objImg; objImg = document.getElementById("imgMain") ; if(objImg.style.visibility == ""){
    objImg.style.visibility = "hidden";
    }
    else{
    objImg.style.visibility = "";
    }
    }function fnContextMenu() {
    window.event.returnValue=false;
    }
    //-->
    </SCRIPT>
    </HEAD><BODY oncontextmenu="fnContextMenu()">
    <form name="fmImgZoom">
    <TABLE id="tbMain" class="TBMain">
    <TR>
    <TD height="20">
    <input type="button" name="ZoomIn" value="ZoomIn" onclick="fnZoomIn()">
    <input type="button" name="ZoomOut" value="ZoomOut" onclick="fnZoomOut()">
    <input type="button" name="Original" value="Original" onclick="setOriginal()">
    <input type="button" name="FitScreen" value="FitScreen" onclick="setFitScreen()">
    <input type="button" name="FitScreen" value="hide/view" onclick="setDisplay()">
    <input id="btnImgInfo" size="50">
    </TD>
    </TR>
    </TABLE>
    <div id="divMain" class="DivMain" onmousedown="fnDivMouseDown()"><img src="22.jpg" id="imgMain" class="imgMain" onload="setInit(this)" onmousedown="fnMouseDown(this)" onmousemove="fnMouseMove()" onmouseup="fnMouseUp()" ></div>
    </form>
    </BODY>
    </HTML>
      

  3.   

    楼上的。你这个程序只是加了放大缩小什么的。图片还是照样可以到处拖呀????
    我要的是如果到了图片的边界,就拖不动鼠标。就像ACSEE看图一样。到了边界就拖不动了。。
      

  4.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> Document </TITLE>
    <style type="text/css">
    body{
    margin : 0px;
    background-color : #999999 ;
    }
    .DivMain {
    position : absolute ;
    text-align : center ;
    overflow : hidden ;
    }
    .DivMenu {
    position : absolute ;
    text-align : left ;
    overflow : hidden ;
    visibility : hidden ;
    }
    .ImgMain {
    position : absolute ;
    overflow : hidden ;
    border : 0px ;
    }
    .TBMain {
    background-color : #CCCCCC ;
    padding : 0px ;
    border : 0px ;
    z-index : 99 ;
    line-height : 18px ;
    }
    </style><SCRIPT LANGUAGE="JavaScript">
    <!-- var originalWidth;
    var originalHeight;
    var ObjDrag;function setInit(objImg) { originalWidth = objImg.width;
    originalHeight = objImg.height;
    fmImgZoom.Original.click();
    }function setOriginal() { var objImg;
    var objDivMain ;
    var intBodyWidth ;
    var intBodyHeight ; intBodyWidth = document.body.clientWidth ;
    intBodyHeight = document.body.clientHeight ; objImg = document.getElementById("imgMain") ;
    objDivMain = document.getElementById("divMain") ; objImg.style.left = 0 ;
    objImg.style.top = 0 ;
    objImg.style.width = originalWidth;
    objImg.style.height = originalHeight;
    objImg.style.zoom = 1 ; objDivMain.style.width = intBodyWidth ;
    objDivMain.style.height = intBodyHeight - 20 ; fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
    }function initImg(objCurrent) { var intBodyWidth ;
    var intBodyHeight ;
    var objTbMain ;
    var objDivMain ; intBodyWidth = document.body.clientWidth ;
    intBodyHeight = document.body.clientHeight ; objTbMain = document.getElementById("tbMain") ;
    objDivMain = document.getElementById("divMain") ; objTbMain.style.top = 0;
    objTbMain.style.height = 20;
    objTbMain.style.width = intBodyWidth;

    objDivMain.style.left = 0 ;
    objDivMain.style.height = intBodyHeight - 20 ;
    objDivMain.style.width = intBodyWidth ; initZoom(objCurrent);
    }function initZoom(obj){ var intObjWidth ;
    var intObjHeight ;
    var intDivHeight ;
    var intZoomRatio ;
    var objDivMain ;
    var objTbMain; objDivMain = document.getElementById("DivMain");
    objTbMain = document.getElementById("tbMain") ; intDivHeight = objDivMain.style.pixelHeight;
    intObjHeight = obj.style.pixelHeight;
    intZoomRatio = intDivHeight / intObjHeight; obj.style.zoom = intZoomRatio ;
    obj.style.top = 0;
    obj.style.left = 0; fnWritePos (obj.style.left,obj.style.top,obj.style.zoom) ;
    }function setFitScreen() { var objImg; objImg = document.getElementById("imgMain") ;
    initImg(objImg);
    }function fnMouseDown(obj) {
    ObjDrag=obj;
    ObjDrag.setCapture();
    ObjDrag.l=event.x-ObjDrag.style.pixelLeft;
    ObjDrag.t=event.y-ObjDrag.style.pixelTop;
    }function fnMouseMove() {
    if(ObjDrag!=null) {
    var objDivMain;
    objDivMain = document.getElementById("DivMain") ;
    if( event.x - ObjDrag.l >= objDivMain.style.pixelLeft){
    ObjDrag.style.left = event.x-ObjDrag.l;
    }
    else{
    ObjDrag.style.left = objDivMain.style.pixelLeft;
    }
    if( event.y - ObjDrag.t >= objDivMain.style.pixelTop){
    ObjDrag.style.top = event.y-ObjDrag.t;
    }
    else{
    ObjDrag.style.top = objDivMain.style.pixelTop;
    }
    fnWritePos(ObjDrag.style.left,ObjDrag.style.top,ObjDrag.style.zoom);
    }
    }function fnMouseUp() {
    if(ObjDrag!=null) {
    ObjDrag.releaseCapture();
    ObjDrag=null;
    }
    }function fnZoomIn() { var objImg; objImg = document.getElementById("imgMain") ;
    objImg.style.zoom = parseFloat(objImg.style.zoom) + 0.01 ;
    fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
    }function fnZoomOut() {
    var objImg;
    objImg = document.getElementById("imgMain") ;
    if(objImg.style.zoom>0.01){
    objImg.style.zoom = parseFloat(objImg.style.zoom) - 0.01 ;
    fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
    }
    }function fnDivMouseDown() {
    if ( event.button == 2 && event.srcElement.id != "imgMain") {
    setOriginal();
    }
    }function fnWritePos(intLeft,intTop,intZoom) {
    var objbtnImgInfo;
    objbtnImgInfo = document.getElementById("btnImgInfo") ;
    objbtnImgInfo.innerText = " ImgLeft:" + intLeft + " ImgTop:" + intTop + " ImgZoom:" + intZoom ;
    }function setDisplay() { var objImg; objImg = document.getElementById("imgMain") ; if(objImg.style.visibility == ""){
    objImg.style.visibility = "hidden";
    }
    else{
    objImg.style.visibility = "";
    }
    }function fnContextMenu() {
    window.event.returnValue=false;
    }
    //-->
    </SCRIPT>
    </HEAD><BODY oncontextmenu="fnContextMenu()">
    <form name="fmImgZoom">
    <TABLE id="tbMain" class="TBMain">
    <TR>
    <TD height="20">
    <input type="button" name="ZoomIn" value="ZoomIn" onclick="fnZoomIn()">
    <input type="button" name="ZoomOut" value="ZoomOut" onclick="fnZoomOut()">
    <input type="button" name="Original" value="Original" onclick="setOriginal()">
    <input type="button" name="FitScreen" value="FitScreen" onclick="setFitScreen()">
    <input type="button" name="FitScreen" value="hide/view" onclick="setDisplay()">
    <input id="btnImgInfo" size="50">
    </TD>
    </TR>
    </TABLE>
    <div id="divMain" class="DivMain" onmousedown="fnDivMouseDown()"><img src="22.jpg" id="imgMain" class="imgMain" onload="setInit(this)" onmousedown="fnMouseDown(this)" onmousemove="fnMouseMove()" onmouseup="fnMouseUp()" ></div>
    </form>
    </BODY>
    </HTML>