首页 > 网站 > WEB开发 > 正文

js div拖拽

2024-04-27 14:17:36
字体:
来源:转载
供稿:网友
js div拖拽

function Drag(id) {   var trag =document.getElementById(flag);   trag.onmousedown = function (e) {     var page = {         event: function (evt) {         var ev = evt || window.event;         return ev;       },       pageX: function (evt) {         var e = this.event(evt);         return e.pageX || (e.clientX + document.body.scrollLeft - document.body.clientLeft);       },       pageY: function (evt) {         var e = this.event(evt);         return e.pageY || (e.clientY + document.body.scrollTop - document.body.clientTop);

      },       layerX: function (evt) {         var e = this.event(evt);         return e.layerX || e.offsetX;       },       layerY: function (evt) {         var e = this.event(evt);         return e.layerY || e.offsetY;       }   }   var x = page.layerX(e);   var y = page.layerY(e);   if (dv.setCapture) {     dv.setCapture();   }else if (window.captureEvents) {     window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);   }   document.onmousemove = function (e) {     var tx = page.pageX(e) - x;     var ty = page.pageY(e) - y;     dv.style.left = tx + "px";     dv.style.top = ty + "px";   }  document.onmouseup = function () {     if (dv.releaseCapture) {     dv.releaseCapture();   }   else if (window.releaseEvents) {     window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);   }  document.onmousemove = null;  document.onmouseup = null;   }   } }


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表