基本上我试图修复Jquery Tools 1.2.6 Scrollable的滚动过去最后一个项目的奇怪习惯,如果项目的数量没有被滚动大小平分。Jquery Tools Scrollable:让它停在最后一个项目
换句话说,如果我有一个包含11个项目的小部件,并且它被设置为每次显示2并且每次单击下一个按钮以滚动到接下来的2个项目时,当涉及到第11个项目时将滚动以便第十一个显示,但在第十二个项目所在的位置有一个空的空间。本质上滚动未来2到视图尽管没有第二个项目的
这里我有一个演示我修复的jsfiddle:http://jsfiddle.net/natepers/6kmuE/21/
我设法得到它停止在最后一个项目通过重置scroll-size
到剩余的物品数量少于scroll-size
;
问题是我无法回到第一个项目。
这里的JavaScript:
var scrollable = $(".scrollable").data("scrollable");
var size = scrollable.getConf().size;
// Catch any requests for items at the end of the list
scrollable.onSeek(function(event, index) {
var self_size = this.getSize();
// Last vsisible item
var last = index + size;
// How many to the last item
var difference = self_size - last;
// How many more than the scroll size
var remainder = index%size;
//reset scroll size for each request
scrollable.getConf().size = size;
// If next request has items but less than the scroll size
if (remainder == 0 && difference < size && difference > 0) {
// Set the scroll size to th enumber of items left
scrollable.getConf().size = difference;
}
//If we're at the end
if (index++ === self_size - size) {
// Set disabled style on next button
$("a.next").addClass("disabled");
}
//If the items are not evenly divided by the scroll size we know we're at the end
if (remainder != 0) {
// Set scroll size to the what's left
scrollable.getConf().size = remainder;
}
});
// Stop scrolling at last item
scrollable.onBeforeSeek(function(event, index) {
var self_index = this.getIndex();
var self_size = this.getSize();
var last = self_index + size;
//If the last visible item is the last item
if (last == self_size) {
// If the next requested item is >= the last item do nothing
if (index > self_index) { return false; }
}
});
感谢您的任何建议或帮助。
这一个作品只是对我很好。非常感谢! –
像老板一样!谢谢。 我不得不在垂直滚动条上使用它,我所要做的就是将width()调用改为height(); –