Jquery Tools Scrollable:使其停止在最后一项
基本上,我试图修复 Jquery Tools 1.2.6 Scrollable 的奇怪习惯,即如果项目数没有除以滚动大小,则滚动到最后一项。
换句话说,如果我有一个包含 11 个项目的小部件,并且将其设置为一次显示 2 个项目,并且每次单击下一个按钮滚动到下 2 个项目时,当涉及到第十一个项目时,它将滚动,以便第 11 个会显示,但右侧有一个空白区域,如果有第 12 个,则该位置会显示。尽管没有第二项,但基本上将下 2 个滚动到视图中
这里我有一个 jsFiddle 演示了我的修复: http://jsfiddle.net/natepers/6kmuE/21/
我设法通过将 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; }
}
});
感谢您的任何建议或帮助。
Basically I'm trying to fix the Jquery Tools 1.2.6 Scrollable's strange habit of scrolling past the last item if the number of items is not evenly divided by the scroll size.
In other words if I have a widget that contains 11 items and it is set to display 2 at a time and each time the next button is clicked to scroll to the next 2 items, when it comes to the eleventh item it will scroll so the eleventh displays but with an empty space to the right where the twelfth item would be were there one. Essentially scrolling the next 2 into the view despite the absence of the second item
Here I have a jsFiddle that demonstrates my fix: http://jsfiddle.net/natepers/6kmuE/21/
I managed to get it to stop at the last item by resetting the scroll-size
to the remaining number of items less than the scroll-size
;
Problem is I can't get it back to the first item.
Here's the 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; }
}
});
Thanks for any suggestions or help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是一个有点老的问题。我遇到过这种情况,上面建议的链接对我的情况没有帮助。在显示固定数量的项目的情况下,上面链接中描述的解决方案效果很好。
但是如果显示的项目数量可能有所不同怎么办?我的任务涉及显示一堆可滚动链接,这些链接一次滚动一个链接。链接文本的长度总是会有所不同。我无法知道某一时刻会显示多少个项目。
这是我想出的插件解决方案:
以下是如何使用此插件:
示例 HTML:
I know it's a bit old question. I came across this situation and the link suggested above did not help in my case. The solution described in the link above works well in case of fixed number of items displayed.
But what if the number of items displayed can vary? My task involved showing bunch of scrollable links that would scroll one link at a time. Invariably, the text of links would vary in length. I had no ways of knowing how many items will be displayed at one point.
Here is the plug-in solution I came up with:
And here is how to use this plug-in:
Sample HTML:
我最近也遇到了同样的问题。下面这篇博客文章中的解决方案似乎对我来说在 jQuery Tools 1.2.6
http://www.jasoncarr.com/technology/jquery-tools-scrollable-stop-scrolling-past-the-end
I recently had this same problem. The solution in this blog post below seems to work well for me in jQuery Tools 1.2.6
http://www.jasoncarr.com/technology/jquery-tools-scrollable-stop-scrolling-past-the-end
当我遇到这个问题时,我正在寻找其他东西,我意识到这有点晚了,但几个月前我遇到了类似的问题,并通过 雷内·舒伯特。建议的解决方案对我来说非常有效:
jQuery 工具可滚动:屏幕上有 3 个项目,但一次滚动一个
干杯
I was looking for something else when I came upon this question, and I realize this is a bit late, but I had a similar problem a few months ago, and found this answer by René Schubert. The proposed solution worked very well for me:
jQuery Tools Scrollable: 3 Items on screen but scroll one at a time
Cheers