var carousel = jQuery('#mycarousel').data('jcarousel');
var index = carousel.size() + 1;
carousel.size(index);
var html = '<li> some html </li>';
carousel.add(index, html);
carousel.scroll(index, 1);
最后一个滚动方法会触发,但并非总是如此。这是JCarousel中的错误吗?
以下是JCarousel中滚动方法的代码:
/**
* Scrolls the carousel to a certain position.
*
* @method scroll
* @return undefined
* @param i {Number} The index of the element to scoll to.
* @param a {Boolean} Flag indicating whether to perform animation.
*/
scroll: function(i, a) {
if (this.locked || this.animating)
return;
this.animate(this.pos(i), a);
}
答案 0 :(得分:1)
@param a {Boolean} Flag indicating whether to perform animation.
参数2是布尔值。你已经指定了一个整数:
carousel.scroll(index, 1);
所以也许这会更好:
carousel.scroll(index, true);
答案 1 :(得分:1)
请尝试这样的事情
var position = 11; // assuming that every page contains 10 elements.
// now this will move your scroll to a desired position (first element to show)
jQuery('#myCarousel').jcarousel('scroll',position);
希望这有帮助!