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>