拖拽

$(function () {

    document.onmousedown = function () {

        var oBox = document.getElementById("box");
        var e = e || window.event;

        var x = e.clientX;
        var _left = parseInt(oBox.style.left) || 0;

        document.onmousemove = function (event) {
            var _clientX = (event || window.event).clientX - x;//鼠标偏移量
            var _divX = _left + _clientX;//div偏移量

            oBox.style.left = _divX + "px";
        }

        document.onmouseup = function () {
            document.onmousemove = null;
            document.onmouseup = null;
        }

    }

});

  

posted @ 2016-06-07 13:55  Mu薇  阅读(152)  评论(0编辑  收藏  举报