drake035
drake035

Reputation: 2877

Why does Ajax reset my window scroll position to zero?

In my page I have a header DIV, a link and a target DIV. The link loads - through jQuery load() - a picture in the target DIV.

Problem : if you scroll a bit down AND THEN click on the link, you'll see that the window scroll position resets to zero. Yet it's an Ajax event, the scroll position should remain exactly the same !

Note that this is true only the first time you click. If you reload the page and click again, the picture will load without scroll position changing (normal behaviour). You have to clean your browser cache if you want to replicate the problem again.

Any idea of what's going on here ?

Upvotes: 0

Views: 1353

Answers (2)

MMM
MMM

Reputation: 7310

It's because your target div changes it's size depending on its child.

If for example you set the height of your target to 866px (the height of the image) and set the height of your child div to something smaller (at the moment its 1000px), you shouldn't experience these problems (at least I don't have this problem anymore under Chrome)

Upvotes: 1

charlietfl
charlietfl

Reputation: 171679

Very simple...you have a div inside target with inline height = 1500px. You are replacing that with ajax so body is shrinking as new content isn't same height

Upvotes: 1

Related Questions