javascript - jquery draggable / droppable change snap -
i attempting create series of drag/droppable divs. once div1 has been dropped, create new div , have snap @ new position. snap position remains same when div1 has been dropped , div2 being dragged: ( http://jsfiddle.net/klpgukkj/2/ )
var trackid = "path0"; var tracktype = "a"; $('.map-track-box').droppable({ tolerance: 'touch', drop: function(event,ui){ // returns home $('#trackdragger').animate({ top: '30px', left: '20px' },500); } }); $('#'+trackid).droppable({ tolerance: 'touch', drop: function(event,ui){ // in position var pos = $('#'+trackid).position(); $('#trackdragger').animate({ top: pos.top, left: pos.left },500,function() { $('#draggerbox').append("<div class='"+tracktype+"' style='z-index:10;position:absolute;top:"+pos.top+"px;left:"+pos.left+"px;'></div>"); $('#trackdragger').css({ top: '30px', left: '20px' },500); $('#trackdragger').attr('class', 'd'); $('#'+trackid).removeclass('ui-droppable'); // attempted remove added class, , add new element, without luck if(trackid=="path0") { trackid = "path1"; }else if(trackid=="path1") { trackid = "path2"; tracktype = "d"; }else if(trackid=="path2") { trackid = "path3"; tracktype = "e"; } $('#'+trackid).addclass('ui-droppable'); }); } }); $('#trackdragger').draggable({ revert: 'invalid', start: function(event,ui) { $('#trackdragger').attr('class', tracktype); }, snap: "#"+trackid, // keeps snapping initial div (path0) though trackid being changed path1,path2 etc snapmode: "inner", stop: function(){ var dragpos = $('#trackdragger').position(); if(dragpos.left < 101 && dragpos.top < 91) { $('#trackdragger').attr('class', 'd'); } //$(this).draggable('option','revert','invalid'); } });
the above works well, dragged element keeps snapping path0 (initial draggable div). there anyway force new snap location ?
thank you
as fiddle you've mentioned, bind droppable
event 1 element. is
$('#'+trackid) // variable don't change "path0" other.
as understand, want other black boxes have droppable event bind.
just change code following in droppable
section.
$('.path').droppable({});
this bind event every .path
element in page.
see updated fiddle here.
Comments
Post a Comment