首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

面临对像的拖拽

2012-11-25 
面向对像的拖拽function Drag(obj){this.oBox document.getElementById(obj)this.disX 0this.disY 0

面向对像的拖拽
function Drag(obj){
   this.oBox= document.getElementById(obj);
   this.disX =0;
   this.disY =0;
   var slef =this;
   this.oBox.onmousedown=function(ev){
      self.dragDown(ev)
  }
}

Drag.prototype={
    dragDown:function(ev){
     
        this.disX =ev.clientX - this.oBox.offsetLeft;
        this.disY = ev.clientY - this.oBox.offsetRight;
        var self = this;
        document.onmousemove = function(ev){
            
           self.dragMove(ev);
        }
         document.onmouseup = function(ev){
            
            document.onmousemove=null;
            document.onmouseup =null;
        }

       return false;
    },
   
   dragMove:function(ev){
    
      var L = ev.clientX -this.disX;
      var Y = ev.clientY - this.disY;
      this.oBox.style.left = L + 'px';
      this.oBox.style.top =Y + 'px';
      
   }
}

热点排行