gpt4 book ai didi

jquery - jCarousel:您可以删除所有项目并重新绑定(bind)到新集合吗?

转载 作者:行者123 更新时间:2023-12-03 22:38:17 24 4
gpt4 key购买 nike

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似乎不起作用。

最佳答案

您可以执行此操作,但需要保留对轮播的引用并对其调用reset。这可以通过使用传递给 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>

关于jquery - jCarousel:您可以删除所有项目并重新绑定(bind)到新集合吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1375171/

24 4 0