jCarousel: Can you remove all items and rebind to a new collection?

前端 未结 2 1115
轻奢々
轻奢々 2021-01-05 09:20

jCarousel documentation states the following:

  • By passing the callback function itemLoadCallback as configuration option, you are able to dynam
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 09:48

    You can do this but you need to keep a reference to the carousel around and call reset on it. This can be achieved by using the initCallback option you pass to the jcarousel function.

    function carousel_callback( carousel, state) {
        // BWA-HA...I have the carousel now....FEEL THE POWER!
    
        // reset empties it out
        $('#reset-caro').click( function( evt ) {
            carousel.reset();
        });
    
        // here's how to call add
        $('#add-to').click( function( evt ) {
            // ..this just adds to the first spot..modify as needed
            carousel.add(0, "
  • O HAI!
  • "); }); } $(document).ready(function() { $('#mycarousel').jcarousel( { initCallback: carousel_callback }); });

    Here's my HTML:

      reset
    
      add  
    
      
    • MOM
    • DAD
    • BROTHER
    • SISTER

提交回复
热议问题