http://www.walterzorn.com/dragdrop/dragdrop_e.htm
好看研究一下。收获一定不小。

解决方案 »

  1.   

    <body  onload="init()">
    <SCRIPT language=JavaScript>
    drag = 0
    move = 0
    function init() {
        window.document.onmousemove = mouseMove
        window.document.onmousedown = mouseDown
        window.document.onmouseup = mouseUp
        window.document.ondragstart = mouseStop
    }
    function mouseDown() {
        if (drag) {
            clickleft = window.event.x - parseInt(dragObj.style.left)
            clicktop = window.event.y - parseInt(dragObj.style.top)
            dragObj.style.zIndex += 1
            move = 1
        }
    }
    function mouseStop() {
        window.event.returnValue = false
    }
    function mouseMove() {
        if (move) {
            dragObj.style.left = window.event.x - clickleft
            dragObj.style.top = window.event.y - clicktop
        }
    }
    function mouseUp() {
        move = 0
    }
    </SCRIPT>
    <div id="block1" onmouseout="drag=0" onmouseover="dragObj=block1; drag=1;" style="height: 60; left: 200; position: absolute; top: 200; width: 120"><dd><img alt border="0" src="../index/logo.gif" width="120" height="60"></dd></div>
    </body>