微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – jCarousel:你能删除所有项目并重新绑定到新的集合吗?

jCarousel documentation声明如下:
  • By passing the callback function itemloadCallback as configuration option,you are able to dynamically create (li) items for the content.
    {…}
  • jCarousel contains a convenience method add() that can be passed the index of the item to create and the innerHTML string of the item to be created.

我的问题:

Is it possible to remove all items and rebind to a new collection?

顺便说一句:我不一定需要一种“便利方法”来做到这一点.我对解决方法非常开放.
仅供参考:This strategy似乎不起作用.

解决方法

你可以这样做,但你需要保持对旋转木马的引用并在其上调用重置.这可以通过使用传递给jcarousel函数的initCallback选项来实现.
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
    });
});

这是我的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>

原文地址:https://www.jb51.cc/jquery/177642.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐