I am trying to scroll to a specific location in a scrolling DIV. Right now I am using a pixel offset with the jQuery scrollTop() function which works great on desktop brows
Temporarily setting the overflow
property to 'hidden', as recommended in @Allan Nienhuis' answer, does not work on Android 4.0.3
, for instance (which is, e.g., what the Kindle Fire 2s are running) - when you set overflow
back to scroll
, the element scrolls back to the top.
Alternatives:
Roll your own scrolling via a helper function, as demonstrated here - while this is simple to implement, it is bare-bones in that it doesn't give you inertial scrolling or overscrolling.
Use a library such as iScroll, which implements its own, sophisticated scrolling (inertial, overscrolling) based on CSS transformations.
Using iScroll requires a bit of setup, though: you need a wrapper div
with fixed height and style overflow: hidden
and the element to scroll should have no overflow
style. This jsFiddle demo shows how it's done.