滚动到列表中的某个项目
我有一个元素列表,我希望能够在用户选择项目时成为焦点。我尝试在这些对象上使用 Jquery 调用 .focus() 但无济于事。我有什么遗漏的吗? :)
编辑: 我有一个元素列表 (ul)。我按住 Shift 键并单击起始项,然后按箭头键继续选择。上下。我真的希望班次选择功能就像在 Finder 或 Windows 资源管理器中一样。当选择不可见的项目时向上滚动(在相同情况下向下滚动)。
有没有方便的 jQuery 插件可以帮我处理这个问题?
编辑2: 想通了一些事情,又确定了一个更大的问题。
现在我正在使用名为scrollTo 的jQuery 插件。我可以使用此插件滚动到列表中的某个元素。但是,“滚动”到某个项目意味着它现在是列表中的第一项,这是不可取的行为。在 Finder 或资源管理器中选择任意数量的项目,您会发现当您使用 Shift-箭头键选择屏幕外的项目时,它只会向下滚动一个项目的空间,而不会使其成为顶部元素。
当然很容易修复。 ;) 我目前正在跟踪顶部屏幕外的当前元素和底部屏幕外的列表中的当前元素。然而,当用户在完成一些滚动后从列表中选择一个项目时,我目前无法判断哪些元素只是在视线之外,从而造成了僵局。
有什么想法吗? :P
I have a list of elements I would like to be able to have brought into focus when the user is selecting items. I've tried calling .focus() with Jquery on these objects to no avail. Is there anything I'm missing? :)
EDIT:
I have a list (ul) of elements. I shift click on a starting item and and press the arrow keys to continue selecting. Up and down. I would really like for the shift selection to function as if it was in Finder or Windows Explorer. Scrolling up when an item is selected that's not visible (and down for the same case).
Are there any handy jQuery plugins to handle this for me?
EDIT2:
Figured out some things and determined a larger problem.
Right now I am using the jQuery plugin called scrollTo. I can scroll to an element of my list using this plugin. However, "scrolling" to an item means it is now the first item in the list, which is NOT desirable behavior. Select any number of items in Finder or Explorer and see that when you shift-arrow select an item that's offscreen, it only scrolls down one item's worth of space and does NOT make it the top element.
Easy to fix of course. ;) I am currently keeping track of the current element just off screen on the top and the current element in the list that's just offscreen on the bottom. However, when the user selects an item out of the list after they have done some scrolling, I currently have no way to tell what elements are just out of sight, creating an impasse.
Any ideas? :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题尚不清楚,但如果您正在谈论自动滚动页面(或元素)以便特定元素位于视口中,您可以尝试 scrollTo 插件。
编辑:您的问题更新可以让您更深入地了解您正在寻找的内容。我不清楚您使用什么方法来实现轮班选择(或者您是否实际上正在扩展问题以询问如何做到这一点)。但假设您仍然只是询问滚动部分,我会在附加到当您将另一个列表项添加到您的选择时触发的事件(自定义?)的函数中添加滚动调用。
例如,假设您每次选择
时都会触发一个名为
list_expanded
的自定义事件,您可以尝试如下操作:显然您也可以使用“常规”事件,例如
点击
,具体取决于多选解决方案的工作方式。It's not clear from your question, but if you're talking about automatically scrolling the page (or element) so that a particular element is in the viewport, you might try the scrollTo plugin.
Edit: Your question update provides a little more insight into what you're looking for. I'm not clear on what method you're using to achieve the shift-selection (or if you're actually expanding the question to ask how to do that). But assuming you're still just asking about the scrolling piece, I would add the scrolling call in a function attached to whichever event (custom?) is fired when you add another list item to your selection.
For example, assuming you're triggering a custom event called
list_expanded
each time an<li>
is selected, you could try something like this:Obviously you can also use a "regular" event like
click
, depending on how your multiple-select solution works.