Jquery draggable droppable supprimer abandonné

Comment supprimer l'article du panier?

Naturellement, vous voudriez pouvoir faire glisser et déposer l'élément.

$(function() { $( "#catalog" ).accordion(); $( "#catalog li" ).draggable({ appendTo: "body", helper: "clone" }); $( "#cart ol" ).droppable({ activeClass: "ui-state-default", hoverClass: "ui-state-hover", accept: ":not(.ui-sortable-helper)", drop: function( event, ui ) { $( this ).find( ".placeholder" ).remove(); $( " " ).text( ui.draggable.text() ).appendTo( this ); } }).sortable({ items: "li:not(.placeholder)", sort: function() { // gets added unintentionally by droppable interacting with sortable // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options $( this ).removeClass( "ui-state-default" ); } }); }); 
  • $(function() { $( "#catalog" ).accordion(); $( "#catalog li" ).draggable({ appendTo: "body", helper: "clone" }); $( "#cart ol" ).droppable({ activeClass: "ui-state-default", hoverClass: "ui-state-hover", accept: ":not(.ui-sortable-helper)", drop: function( event, ui ) { $( this ).find( ".placeholder" ).remove(); $( " " ).text( ui.draggable.text() ).appendTo( this ); } }).sortable({ items: "li:not(.placeholder)", sort: function() { // gets added unintentionally by droppable interacting with sortable // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options $( this ).removeClass( "ui-state-default" ); } }); });

    Cela devrait fonctionner:

     $(function() { $("#catalog").accordion(); $("#catalog li").draggable({ appendTo: "body", helper: "clone" }); $("#cart ol").droppable({ activeClass: "ui-state-default", hoverClass: "ui-state-hover", accept: ":not(.ui-sortable-helper)", drop: function(event, ui) { $(this).find(".placeholder").remove(); $("<li></li>").text(ui.draggable.text()) .addClass("cart-item") .appendTo(this); } }).sortable({ items: "li:not(.placeholder)", sort: function() { $(this).removeClass("ui-state-default"); } }); $("#catalog ul").droppable({ drop: function(event, ui) { $(ui.draggable).remove(); }, hoverClass: "ui-state-hover", accept: '.cart-item' }); }); 

    Notes :

    • Lorsqu'un article est déposé sur la zone du panier, j'ai ajouté une classe d' cart-item de cart-item au nouvel élément.
    • J'ai fait le catalogue ul droppable; Cette zone n'accepte que l' cart-item s. Il appelle remove() pour supprimer un article du panier une fois que la baisse est survenue.

    Voyez-le travailler ici: http://jsfiddle.net/andrewwhitaker/t97FE/embedded/result/

    Vous pouvez faire glisser un article du panier vers n'importe quelle catégorie du catalogue, mais je pense qu'il serait très facile de rendre les articles uniquement glissants dans leurs catégories d'origine.