TouchScroll is a JavaScript- and CSS 3-based scroller for devices using Webkit Touch (yes, that includes Android). It is meant to mimic “native” scrolling feeling and behavior as much as possible.
This demo works best on iPhone, iPad and in WebKit Nightly. Safari 4 kind of works, too.
While Safari Mobile features native scrolling, there are two reasons to re-implement scrolling with JavaScript: The original scrolling behavior is rather slow – we were looking for a solution that feels more fluid. And the viewport behavior of Mobile Safari and other mobile browsers using WebKit doesn’t allow for fixed positioned elements.
TouchScroll uses a combination of JavaScript and CSS 3. All animations are done with CSS transitions – no JavaScript intervals. That means, the deceleration animation can be configured with a bezier curve.
The elasticity effect when crossing the scroller bounds is achieved by dividing the bezier curve into two sub-curves using my (yet to be finished) CSS Bezier library for JavaScript.
On Safari mobile TouchScroll benefits from hardware acceleration for CSS transforms and transitions, which allows for very smooth scrolling. Android hasn’t any hardware support, which makes the animations choppier than on Apples devices.
The scroller updates its dimensions and position automatically on window resizes (window.onresize
), orientation changes (window.onorientationchange
) and DOM modifications inside the scroller (DOMSubtreeModified
event). It only needs to be updated manually when it wasn’t visible on initialization (or last update) as soon it is made visible again.
TouchScroll allows you to customize many aspects of the scrolling behavior. The following aspects are configurable:
TouchScroll is released under a BSD license. You can find more information on how to get TouchScroll on our blog.
For more information contact me via mail, follow me on twitter (@void_0) and watch out for the TouchScroll blog post on our blog.
Photo: “olympic montage 01” by Daveybot – cc licensed.