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

六月ゝ 毕业季﹏ 提交于 2019-11-30 19:49:38

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, "<li>O HAI!</li>");
    });
}

$(document).ready(function() {
    $('#mycarousel').jcarousel( {
        initCallback: carousel_callback
    });
});

Here's my HTML:

  <a id="reset-caro" href="#">reset</a>

  <a id="add-to" href="#">add</a>  

  <ul id="mycarousel" class="jcarousel-skin-tango">
    <li>MOM</li>
    <li>DAD</li>
    <li>BROTHER</li>
    <li>SISTER</li>
  </ul>

In addition to the above, please also specify the size of your new carousel.

carousel.size(x);

This should eliminate the white empty boxes in IE (as described above).

Thanks, Nik

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!