iPhone-style scroll bar in web app with auto fade in/out
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.
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
<div id="scrollbar1" style="visibility: hidden">
<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>
<div class="viewport">
<div class="overview">
<h3>Magnis dis parturient montes</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vitae velit at velit pretium sodales. Maecenas egestas imperdiet mauris, vel elementum turpis iaculis eu. Duis egestas augue quis ante ornare eu tincidunt magna interdum. Vestibulum posuere risus non ipsum sollicitudin quis viverra ante feugiat. Pellentesque non faucibus lorem. Nunc tincidunt diam nec risus ornare quis porttitor enim pretium. Ut adipiscing tempor massa, a ullamcorper massa bibendum at. Suspendisse potenti. In vestibulum enim orci, nec consequat turpis. Suspendisse sit amet tellus a quam volutpat porta. Mauris ornare augue ut diam tincidunt elementum. Vivamus commodo dapibus est, a gravida lorem pharetra eu. Maecenas ultrices cursus tellus sed congue. Cras nec nulla erat.</p>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque eget mauris libero. Nulla sit amet felis in sem posuere laoreet ut quis elit. Aenean mauris massa, pretium non bibendum eget, elementum sed nibh. Nulla ac felis et purus adipiscing rutrum. Pellentesque a bibendum sapien. Vivamus erat quam, gravida sed ultricies ac, scelerisque sed velit. Integer mollis urna sit amet ligula aliquam ac sodales arcu euismod. Fusce fermentum augue in nulla cursus non fermentum lorem semper. Quisque eu auctor lacus. Donec justo justo, mollis vel tempor vitae, consequat eget velit.</p>
<p>Vivamus sed tellus quis orci dignissim scelerisque nec vitae est. Duis et elit ipsum. Aliquam pharetra auctor felis tempus tempor. Vivamus turpis dui, sollicitudin eget rhoncus in, luctus vel felis. Curabitur ultricies dictum justo at luctus. Nullam et quam et massa eleifend sollicitudin. Nulla mauris purus, sagittis id egestas eu, pellentesque et mi. Donec bibendum cursus nisi eget consequat. Nunc sit amet commodo metus. Integer consectetur lacus ac libero adipiscing ut tristique est viverra. Maecenas quam nibh, molestie nec pretium interdum, porta vitae magna. Maecenas at ligula eget neque imperdiet faucibus malesuada sed ipsum. Nulla auctor ligula sed nisl adipiscing vulputate. Curabitur ut ligula sed velit pharetra fringilla. Cras eu luctus est. Aliquam ac urna dui, eu rhoncus nibh. Nam id leo nisi, vel viverra nunc. Duis egestas pellentesque lectus, a placerat dolor egestas in. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae ipsum non est iaculis suscipit.</p>
<h3>Adipiscing risus </h3>
<p>Quisque vel felis ligula. Cras viverra sapien auctor ante porta a tincidunt quam pulvinar. Nunc facilisis, enim id volutpat sodales, leo ipsum accumsan diam, eu adipiscing risus nisi eu quam. Ut in tortor vitae elit condimentum posuere vel et erat. Duis at fringilla dolor. Vivamus sem tellus, porttitor non imperdiet et, rutrum id nisl. Nunc semper facilisis porta. Curabitur ornare metus nec sapien molestie in mattis lorem ullamcorper. Ut congue, purus ac suscipit suscipit, magna diam sodales metus, tincidunt imperdiet diam odio non diam. Ut mollis lobortis vulputate. Nam tortor tortor, dictum sit amet porttitor sit amet, faucibus eu sem. Curabitur aliquam nisl sed est semper a fringilla velit porta. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum in sapien id nulla volutpat sodales ac bibendum magna. Cras sollicitudin, massa at sodales sodales, lacus tortor vestibulum massa, eu consequat dui nulla et ipsum.</p>
<p>Aliquam accumsan aliquam urna, id vulputate ante posuere eu. Nullam pretium convallis tincidunt. Duis vitae odio arcu, ut fringilla enim. Nam ante eros, vestibulum sit amet rhoncus et, vehicula quis tellus. Curabitur sed iaculis odio. Praesent vitae ligula id tortor ornare luctus. Integer placerat urna non ligula sollicitudin vestibulum. Nunc vestibulum auctor massa, at varius nibh scelerisque eget. Aliquam convallis, nunc non laoreet mollis, neque est mattis nisl, nec accumsan velit nunc ut arcu. Donec quis est mauris, eu auctor nulla. Fusce leo diam, tempus a varius sit amet, auctor ac metus. Nam turpis nulla, fermentum in rhoncus et, auctor id sem. Aliquam id libero eu neque elementum lobortis nec et odio.</p>
</div>
</div>
</div>
Then a jQuery function to make it fade out and in:
$(function() {
$("#scrollbar1").bind('hover', function() {
// On hover fade in
$(this).fadeIn(1000);
});
$("#scrollbar1").bind('mouseout', function() {
// On mouseout fade out
$(this).fadeOut(1000);
});
});
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:
$('#content').innerscroll({
destination: $('#wrapper')
});
where content
is the element that is overflowing. Some minor additional setup is that you need to create a parent element wrapper
for content
with almost identical dimensions, but only a slightly smaller width (to hide content
'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.
I found Nanoscroller JS to be the most reliable scrollbar replacer that supports this style. http://jamesflorentino.github.com/nanoScrollerJS/
精彩评论