js基础拖拽一

	var oDiv= document.getElementById("div");
	oDiv.οnmοusedοwn= function(e){
		var _this = this;
		var e= e || window.event;
		var diffX= e.clientX - _this.offsetLeft;
		var diffY= e.clientY - _this.offsetTop;
	     document.οnmοusemοve= function(e){
			 var e= e || window.event;
			 _this.style.left= e.clientX -diffX + "px";
			 _this.style.top= e.clientY -diffY + "px";
		 
		 }
		 document.οnmοuseup= function(e){
			 this.οnmοusemοve= null
			 this.οnmοuseup= null
		 }
	}

 

转载于:https://www.cnblogs.com/fangxuele/p/5433305.html

你可能感兴趣的:(js基础拖拽一)