javascript - Drag all Divs. "this" -


i have code dnd element. works especific element. wanna make work divs. can't reference "this.id" move function. don't missing make work.

window.addeventlistener('load', init, false); function init(){        //just 1 element    /* box = document.getelementbyid('div1');     box.addeventlistener('mousedown', startmoving, false);     box.addeventlistener('mouseup', stopmoving, false);*/       //all element?     box = document.getelementsbytagname('div');     (i=0;i<box.length;i++) {         box[i].addeventlistener('mousedown', startmoving, false);         box[i].addeventlistener('mouseup', stopmoving, false);     }  }   function startmoving(evt){    evt = evt || window.event;    var posx = evt.clientx,     posy = evt.clienty,    = document.getelementbyid(this.id);    divtop = parseint(a.style.top),    divleft = parseint(a.style.left);     var diffx = posx - divleft,     diffy = posy - divtop;      document.onmousemove = function(evt){      evt = evt || window.event;     var posx = evt.clientx,      posy = evt.clienty,      ax = posx - diffx,      ay = posy - diffy;     move(this.id,ax,ay);          }     } function stopmoving(){   document.onmousemove = function(){}  }    function move(divid,newx,newy){     var = document.getelementbyid(divid);     a.style.left = newx + 'px';     a.style.top = newy + 'px';     } 

is there better way make this?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -