快捷导航

作为前端小白的我,试着用面向对象的方式写了一个拖拽,麻烦大神指正下哪里

Drag.prototype = {
    mousedown: function(dom) {
        var that = this;
        dom.onmousedown=function(e) {
            var ev=e || event;
            that.disX=ev.clientX-dom.offsetLeft;
            that.disY=ev.clientY-dom.offsetTop;
            document.onmousemove=function(e){
                var ev=e||event;
                dom.style.left=ev.clientX-that.disX+'px';
                dom.style.top=ev.clientY-that.disY+'px';

            };
            that.mouseup();
        };

    },
    mouseup: function () {
        document.onmouseup=function () {
            document.onmousemove=null;
            document.onmouseup=null;
        }
    },
    init:function (dom){
        this.mousedown(dom);

    }
};
var dd = new Drag();
var oDiv= document.getElementById('div1');
dd.init(oDiv);

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

有点觉得呢,你的代码写的似乎不怎么整洁,像函数里的函数,或者闭包这种东西也不要乱用,起码也要学懂了,不然会有问题的
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP