javascript - Jquery Draggable and Droppable with Multiple Draggable -
kind of new jquery , working draggable , droppable stuff. have 2 draggables , droppable. can't quite figure out how make different things based on box drop. here jquery:
$(function() { $( "#greatplan" ).draggable(); $( "#droppable" ).droppable({ drop: function( event, ui ) { $( ) .addclass( "ui-state-highlight" ) .find( "p" ) .html( "great plan picked!" ) } }); $( "#poorplan" ).draggable(); $( "#droppable" ).droppable({ drop: function( event, ui ) { $( ) .addclass( "ui-state-highlight" ) .find( "p" ) .html( "poor plan picked!" ) } }); })
and html:
<div id="greatplan" class="ui-widget-content"> <p>great plan!</p> </div> <br> <div id="poorplan" class="ui-widget-content"> <p>poor plan!</p> </div> <div id="droppable" class="ui-widget-header"> <p>drop plan here</p> </div> no matter box drag droppable "poor plan!". ideas?
you need one drop handler, test draggable element dropped.
$(function() { $("#greatplan").draggable(); $("#poorplan").draggable(); $("#droppable").droppable({ drop: function (event, ui) { switch (ui.draggable.attr('id')) { case "greatplan": $(this).addclass("ui-state-highlight").find("p").html("great plan picked!"); break; case "poorplan": $(this).addclass("ui-state-highlight").find("p").html("poor plan picked!") break; } } }); });
Comments
Post a Comment