iOS Overflow scrollToTop

Replacement for missing scrollToTop of -webkit-overflow-scrolling:touch;

View the Project on GitHub prud/ios-overflow-scroll-to-top

iOS Overflow ScrollToTop

Using -webkit-overflow-scrolling:touch provides native-like scrolling on iOS web apps. However, when using it on any element other than document.body, it will break the native scroll-to-top behavior when tapping the status bar. This tiny script provides a replacement that even works when the scrollarea is currently bouncing or in momentum / inertia.

Check the demo on your iOS device (short: goo.gl/6HJ9oG). Scroll down and tap the header to scroll up.

Usage

headerEl.addEventListener('click', function() {
  window.scrollToTop(contentEl);
});

contentElement can be a DOM element or a CSS-like selector.

Compatibility

The script should work on all iOS 5+ devices (both browser and UIWebView). The demo has been tested on:

Known issues

Why won't it scroll to top when I tap the status bar?

If you're building a web app for Mobile Safari it is not possible to listen for events on the status bar. However, if you're working with a UIWebView, you can actually achieve this with some native code. Read this StackOverflow question on how to detect status bar touches