0

我正在尝试获取最新的 jQuery 工具的 Scrollable,以便在到达终点后返回第一项。我目前水平显示 4 个项目,使用下一个/上一个按钮一次移动 1 个项目。有一个名为“循环”的属性,但直到最后一个项目在唯一显示的项目中才会生效。到达最后一项后,我需要停止可滚动,然后将其滚动到第一项。

我已经尝试了一些事情,例如:

jQuery(function() {
    // Initialize the Scrollable control
    jQuery(".scrollable").scrollable();
    // Get the Scrollable control
    var scrollable = jQuery(".scrollable").data("scrollable");
    // Set to the number of visible items
    var size = 4;

    // Handle the Scrollable control's onSeek event
    scrollable.onSeek(function(event, index) {
      // Check to see if we're at the end
      if (this.getIndex() >= this.getSize() - size) {
         // Disable the Next link
         jQuery("a.next").addClass("disabled");
       }
    });

   // Handle the Scrollable control's onBeforeSeek event
      scrollable.onBeforeSeek(function(event, index) {
      // Check to see if we're at the end
        if (this.getIndex() >= this.getSize() - size) {
        // Check to see if we're trying to move forward
          if (index > this.getIndex()) {
            // Cancel navigation
            scrollable.seekTo(0,1000);
          }
        }
      });
});

同样,问题是,直到显示 4 个空项目中的 2 个,循环才开始触发,然后它将填充另外两个,我想知道是否有可能使这更平滑并且永远不会有空项目显示。

[网站已删除]

4

1 回答 1

0

通过将 jQuery 工具从 v1.2.7 恢复到 v1.2.5 解决的问题

我使用以下代码来检测它何时到达末尾,然后在到达末尾时滚动到项目列表的开头。

var $scroller = $('.scrollable').scrollable({onBeforeSeek:carousel}).autoscroll().data('scrollable');

$items = $('.scrollable .items div');
function carousel(e, idx) {
    // set this to 4 so it stops after 4 items
    if(idx > $scroller.getSize() - 4) {
        // return the beginning
        $scroller.seekTo(0).stop();
        // stop when we reach the end
        return false;
    }
}
于 2013-05-02T21:02:34.643 回答