Web 应用程序中的 iPhone 风格滚动条,具有自动淡入/淡出功能
我正在制作一个网络应用程序,并且非常喜欢自动淡入和淡出的 iPhone 风格的滚动条。我以前只在iOS产品上见过它,但现在Facebook似乎已经在Chat联系人列表中实现了它。
为什么我这么喜欢它?它会自动淡入和淡出,因此不那么引人注目,并且可以节省大量空间。当它显示时,它实际上位于 div 内部,而不是围绕它,再次有效地利用了空间。
关于如何做到这一点有什么想法吗?它不是 Matteo Spinelli 的“iScroll”,它采用“正常”滚动条(对于 iOS 产品来说当然是 iOS 风格)在 div 上使用。
我尝试使用 Jonathan Azoff 的 Overscroll Jquery 插件,但我似乎无法让它完全正常工作。我设法让滚动条在 mouseenter 上自动淡入和淡出(就像 Facebook 所做的那样),但浏览器之间的滚动行为有所不同(并且似乎在 OSX 上的速度和惯性方面覆盖了浏览器的滚动行为)。快速浏览一下源代码似乎与这个结论是一致的。
是否有其他插件/库可以用来精确维护浏览器的滚动行为,但滚动条可以自动淡入和淡出,并且看起来像 iOS 风格?
编辑:决定自己做。请参阅下面的答案。
I'm making a web app and really like the iPhone-style scrollbars that automatically fade in and out. I had only ever seen it on iOS products, but now it seems that Facebook has implemented it in the Chat contact list.
Why do I like it so much? It fades in and out automatically, thus it is less obtrusive and can save significant amounts of space. When it is in display, it's effectively inside the div, instead of around it, again making efficient use of space.
Any ideas on how to do this? It is not Matteo Spinelli's "iScroll" which adopts the "normal" scrollbar (which for iOS products is of course iOS-style) for use on divs.
I've tried to use Jonathan Azoff's Overscroll Jquery plugin, but I can't seem it to get it to work exactly right. I managed to get the scroll bars to fade in and out automatically on mouseenter (like Facebook does) but scrolling behaviour differs between browsers (and does seems to be overriding the browser's scrolling behaviour in both speed and inertia on OSX). A quick glance at the source code seems consistent with this conclusion.
Are there any other plugins/libraries out there that I can use to maintain precisely the browser's scrolling behaviour but have scroll bars that fade in and out automatically and look iOS-style?
EDIT: Decided to make it myself. See answer below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
抱歉,您花了这么长时间才得到这么简单问题的答案...这接近我认为您正在寻找的内容 http://baijs.nl/tinyscrollbar/。然后,对于淡出,只需使用这样的简单函数即可。
首先是 HTML
,然后是 jQuery 函数使其淡出和淡入:
Sorry it's taken you so long to get an answer to such a simple question... Here is close to what I think you are looking for http://baijs.nl/tinyscrollbar/. Then for the fading out just use a simple function such as this.
First for the HTML
Then a jQuery function to make it fade out and in:
谢谢您的意见,孙子。我看过tinyscroll,它相当不错,但我认为它还不够完美。特别是,在 Firefox(在我的 MacBook 上)中,我失去了平滑滚动的能力(并且滚动最终以离散/量化的量进行)。快速浏览一下代码表明这是由于他们手动处理输入事件并根据这些事件调用滚动的方式造成的。我真的很想保留绝对本机的滚动性能和行为。
所以我编写了自己的 jQuery 插件,innerscroll。我已经在 github 上开源了它。 此处也提供了演示。只需包含我的文件并添加 3 行代码:
其中
content
是溢出的元素。一些小的额外设置是,您需要为content
创建一个父元素wrapper
,其尺寸几乎相同,但宽度稍小(以隐藏content
code> 的本机滚动条)。wrapper
也是放置新的淡入淡出滚动条的位置。我确信存在错误。任何意见、批评或建议将不胜感激。
Thanks for your input, sun-tzu. I've taken a look at tinyscroll and it is quite nice, but I decided it's not quite perfect enough. In particular, in Firefox (on my macbook) I lose smooth scrolling (and scrolling ends up being in discrete/quantized amounts). A quick glance at the code suggests that this is due to the way they manually process input events and invoke scrolling accordingly to these events. I'd really like to preserve absolutely native scrolling performance and behaviour.
So I wrote my own jQuery plugin, innerscroll. I have open-sourced it on github. A demo is also available here. Just include my file and add 3 lines of code:
where
content
is the element that is overflowing. Some minor additional setup is that you need to create a parent elementwrapper
forcontent
with almost identical dimensions, but only a slightly smaller width (to hidecontent
's native scrollbar).wrapper
is also where the new, fading scrollbar will be placed.I'm sure there are bugs. Any comments, critique or suggestions would be appreciated.
我发现 Nanoscroller JS 是支持这种风格的最可靠的滚动条替代品。 http://jamesflorentino.github.com/nanoScrollerJS/
I found Nanoscroller JS to be the most reliable scrollbar replacer that supports this style. http://jamesflorentino.github.com/nanoScrollerJS/