jQuery - 在 div 内滚动?滚动到?
我有一个带有列表的 div 容器,该列表中只有一项一次性可见,其余项目被隐藏(容器具有溢出:隐藏)。
我希望 jQuery 在单击确切的链接后显示请求的项目:
任何想法? scrollTo 会帮助我吗?我尝试过这个插头,但没有成功。我宁愿不使用 iframe。
I have a div container with list in it, only one item of this list is visible at once and the rest is being hidden (the container has overflow: hidden).
I want jQuery to show the requested items after clicking exact links:
Any ideas? Will scrollTo help me? I've tried this plug but no luck. I'd rather not use an iframe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
ScrollTo 会有所帮助,但是滚动是绝对必要的吗?我认为最好只使用
slideUp()
和slideDown()
我对 HTML 进行了一些修改,为幻灯片项目提供了一个类和一个 id。
现场演示: http://jsfiddle.net/ztFWv/1/
JS
更新
如果您必须滚动:)
这是一个示例:http://jsfiddle.net/ztFWv/3/
包含 scrollTo JS 文件并以这种方式使用命令。
ScrollTo would help, but is scrolling absolutely required? I think it's even better to just use
slideUp()
andslideDown()
I modified the HTML just a bit to give the slide items a class and an id.
Live Demo: http://jsfiddle.net/ztFWv/1/
JS
UPDATE
If you must have scrolling :)
Here is a sample: http://jsfiddle.net/ztFWv/3/
Include the scrollTo JS file and use the command this way.
我最喜欢的方法是向标签添加
tabindex="0"
属性,然后在元素上调用focus()
,这将使浏览器将其滚动到看法。它并没有给你太多的控制权,但它是原生滚动并且非常流畅。
My favorite way to do this, is to add
tabindex="0"
attribute to the tag and then callfocus()
on the element which will make the browser scroll it into view.It doesn't give you alot of control but it's native scrolling and very smooth.
请参阅这些:
如何使用 JQuery $.scrollTo( ) 函数
See these:
How to scroll the window using JQuery $.scrollTo() function
是的,使用 scrollTo jQuery 插件。
使用起来很简单。我自己已经在几个项目中使用过它。
还有其他方法,例如 TABS 或隐藏和显示 div,带或不带动画。我更喜欢这种方法,因为它看起来更专业。
Yes, use the scrollTo jQuery plugin.
It's a doddle to use. I've used it myself for several projects.
There are other ways, such as TABS or hiding and showing divs, with or without animation. I prefer this method as it looks more professional.
我今天已经玩了几个小时的滚动等,并想出了一个我认为是没有滚动条的简洁滚动框架,类似于这里所要求的。它进行垂直滚动,一次滚动一个“页面”或滚动到特定元素(例如 DIV)。它还可以水平滚动,一次滚动一页或滚动到特定元素(例如 SPAN)。
在 this fiddle 中查看它的实际效果
HTML 示例是:
CSS 是:
javascript 是:
I've been playing around with scrolling etc. for several hours today and have come up with what I think is a neat framework for scrolling without scrollbars, similar to what was asked for here. It does vertical scrolling, either a "page" at a time or to a specific element (e.g. a DIV). It also does horizontal scrolling, either a page at a time or to a specific element (e.g. a SPAN).
See it in action at this fiddle
The example HTML is:
The CSS is:
The javascript is: