怎么样实现鼠标托动div???

解决方案 »

  1.   

    //移动DIV,只要将div的id传给函数即可!!
    <div id="div1" onmousemove="Move_obj('div1')">移动移动 </div>js:
    <script type="text/javascript">
    var drag_ = false
    var D = new Function('obj', 'return document.getElementById(obj);')
    var oevent = new Function('e', 'if (!e) e = window.event;return e')function Move_obj(obj) {
        var x, y;
        D(obj).onmousedown = function(e) {
            drag_ = true;
            with (this) {
                style.position = "absolute"; var temp1 = offsetLeft; var temp2 = offsetTop;
                x = oevent(e).clientX; y = oevent(e).clientY;
                document.onmousemove = function(e) {
                    if (!drag_) return false;
                    with (this) {
                        style.left = temp1 + oevent(e).clientX - x + "px";
                        style.top = temp2 + oevent(e).clientY - y + "px";
                    }
                }
            }
            document.onmouseup = new Function("drag_=false");
        }
    }
    </script>
      

  2.   

    膜拜学习,不过确实jquery里面的ui可以实现
    不妨试试