Scrollerometer: Auto-scrolling in Mobile Safari using the Accelerometer
Sunday, December 19th, 2010In iOS 4.2, Apple introduced the ability to access the accelerometer via Mobile Safari. Other native iOS applications offer a feature of auto-scrolling forwards and backwards when an iOS device is tilted. With access to the accelerometer data, I wanted to see if I could recreate this same feature in Mobile Safari.
The initial implementation only took about 4 lines of code and was fairly simple. I just updated the top scroll position of the page based on the y tilt of the device. From there I just added things like reseting the initial tilt of the device when you load the page and allowing to to reset it manually with a button.
You can view the final example on your iOS device here. Keep in mind that you must have iOS 4.2 for this to work.