Getting and setting scroll position
I relied on jQuery to handle getting and setting scroll position in BeerCamp 2011, but after taking another look, its pretty easy to do with modern browsers.
// get scroll position
var x = window.scrollX,
y = window.scrollY;
// set scroll position to x: 140, y: 700
window.scrollTo( 140, 700 );
You might see pageXOffset
and pageYOffset
, as these properties are the same as scrollX
and scrollY
. Old IE doesn’t support either.