5

I am using jQuery UI Droppable Cart Demo plugin and I want to create a carousel or arrows once Dropped area reaches 5 elements... If I click on Arrows, remaning should show


FIDDLE


HTML

<div id="products">
  <h2>Drag</h2>
  <div id="catalog">
      <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
        <li>Item 4</li>
        <li>Item 5</li>
        <li>Item 6</li>
      </ul>
  </div>
</div>

<div id="cart">
  <h2>Drop Here...</h2>
  <div class="ui-widget-content">
    <ol>
      <li class="placeholder">Add your items here</li>
    </ol>
  </div>
</div>

jQuery

$(function() {
    $( "#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() ).appendTo( this );
        }
    }).sortable({
        items: "li:not(.placeholder)",
        sort: function() {
            $( this ).removeClass( "ui-state-default" );
        }
    });
});

Screenshots...


Till 5 Elements

5 Elements to Droppable Area


After 5 Elements Dragged

Create Carousel after 5 elements

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Reddy
  • 1,477
  • 29
  • 79

1 Answers1

2

You can change your jQuery function to this:

$(function() {
   $( "#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() ).appendTo( this );

           if($('.ui-droppable li').length > 5) {
               //bind your carousel here
           }

       }
   }).sortable({
       items: "li:not(.placeholder)",
       sort: function() {
           $( this ).removeClass( "ui-state-default" );
       }
   });
});
valar morghulis
  • 2,007
  • 27
  • 34
  • Excellent @ Franky... This is what exactly I am looking out for... Thanks a TON – Reddy Apr 23 '15 at 06:17
  • Hi @ Franky... there is still some issue.. sorry for late... whenever I am trying to drag the
  • element, css class for
  • is getting removed ... how can I get back the same class from dragged area... please find the updated [*** UPDATED FIDDLE HERE FOR YOUR REFERENCE ***](http://jsfiddle.net/ReddyPrasad/kux7x16y/2/)
  • – Reddy Apr 23 '15 at 08:50
  • use the class here `$( "
  • " )` i think this was what you want if not let me know of the same. – valar morghulis Apr 23 '15 at 09:44
  • @ Franky Thanks for the reply... I am sorry, but that should give same class to every li element... I found the answer, i.e. `$(ui.draggable).appendTo(this);` – Reddy Apr 23 '15 at 10:24