user1834185
user1834185

Reputation: 43

How do I determine and set height and scrolling position from window in jQuery?

I want to get the (vertical and horizontal) scrollbar positions from a loaded html page. Then after making a backend task (e. G. deleting operation) i want to reload the page and set the old positions from scrollbar.

So how can i make this with jquery? (Getting scrollbar positions and setting it later again) I use jquery 1.8.3 at the moment. I tried some ideas, but nothing worked really.

Thanxs for your answers.

Upvotes: 1

Views: 386

Answers (1)

Boris Gappov
Boris Gappov

Reputation: 2493

Use

window.onscroll = function (oEvent) {
  // called when the window is scrolled.
}

and

// get scroll position
var x = window.scrollX,
    y = window.scrollY;

for get scroll position, then save x and y to cookie. After refresh read them from cookie and use code to set scroll position:

window.scrollTo( x, y );

Upvotes: 1

Related Questions