/*********************************************** * Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit http://www.dynamicdrive.com/ for this script and 100s more. ***********************************************/ var dragobject={ z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0, initialize:function(){ document.onmousedown=this.drag; document.onmouseup=function(){this.dragapproved=0;} }, drag:function(e){ var evtobj=window.event? window.event : e; this.targetobj=window.event? event.srcElement : e.target; if (this.targetobj.className.indexOf("drag")>=0){ this.dragapproved=1; //this.newTargetObj = this.targetobj.parentNode; this.newTargetObj = document.getElementById(this.targetobj.getAttribute("dragTarget")); if (isNaN(parseInt(this.newTargetObj.style.left))){this.newTargetObj.style.left="0px";} if (isNaN(parseInt(this.newTargetObj.style.top))){this.newTargetObj.style.top="0px";} this.offsetx=parseInt(this.newTargetObj.style.left); this.offsety=parseInt(this.newTargetObj.style.top); this.x=evtobj.clientX; this.y=evtobj.clientY; if (evtobj.preventDefault) evtobj.preventDefault(); document.onmousemove=dragobject.moveit; } }, moveit:function(e){ var evtobj=window.event? window.event : e; if (this.dragapproved==1){ this.newTargetObj.style.left=this.offsetx+evtobj.clientX-this.x+"px"; this.newTargetObj.style.top=this.offsety+evtobj.clientY-this.y+"px"; return false; } } } dragobject.initialize();