2010-05-14 26 views
1
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滾動方法並不總是觸發

以下是在的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); 
} 

回答

1

@param a {Boolean} Flag indicating whether to perform animation.

參數2是一個布爾值。您指定一個整數:

carousel.scroll(index, 1);

所以,也許這將更好地工作:

carousel.scroll(index, true);

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); 

希望這有助於!