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);
作為前端小白的我,試著用面向?qū)ο蟮姆绞綄?xiě)了一個(gè)拖拽,麻煩大神指正下哪里寫(xiě)得不好。
慕田峪8701529
2017-11-26 10:47:50