我正在尝试让最新的jQuery工具的滚动条在到达末尾后返回到第一项。我当前水平显示4个项目,使用下一步/上一步按钮一次移动一项。有一个名为“circular”的属性,但它直到最后一项出现在唯一显示的项中时才会生效。一旦到达最后一项,我需要停止可滚动,然后将其滚动到第一项。
我已经尝试了一些东西,比如:
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个显示,然后它将填充另外两个,我想知道是否可以让它更平滑,并且永远不会有空项显示。
网站已删除
发布于 2013-05-03 05:02:35
已通过将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;
}
}
https://stackoverflow.com/questions/16346976
复制相似问题