添加5个元素后创建轮播

时间:2015-04-23 04:04:15

标签: jquery jquery-ui jquery-droppable

我正在使用jQuery UI Droppable Cart Demo插件,我想创建一个旋转木马或箭头一旦Dropped area达到5个元素......如果我点击Arrows,remaning应该显示

  

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" );
        }
    });
});
  

截图...

直到5个元素

5 Elements to Droppable Area

拖动5个元素后

Create Carousel after 5 elements

1 个答案:

答案 0 :(得分:2)

您可以将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 );

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

       }
   }).sortable({
       items: "li:not(.placeholder)",
       sort: function() {
           $( this ).removeClass( "ui-state-default" );
       }
   });
});