Gigg
Gigg

Reputation: 1049

Ajax changes scroll position

I have a short question for you. Could anybody help me figure out why after an Ajax request, the page scroll is changing back to the top? I think it's about JQuery. I can't find too much info on the web, so I ask for your help. This is the test page where I'm doing that. Try changing and see what is happening. Thank you so much!

www.*.ca/test/script.php

Got the answear. Thank's

Upvotes: 0

Views: 1605

Answers (2)

dave.evenson
dave.evenson

Reputation: 21

I just ran into this situation with some embedded pagination and I came up with a trick for dealing with it. On page load I grab the calculated pixel height of the content div and then set that fixed height back onto itself. This keeps the div at a fixed size while the page contents are destroyed and replaced.

var height=$('#content').height();
$('#content').height(height);

Or more briefly:

$('#content').height($('#content').height());

Upvotes: 2

Bemmu
Bemmu

Reputation: 18217

Because the page momentarily becomes shorter, so the scrolling position cannot remain where it was or else the page would be scrolled past its contents.

Upvotes: 1

Related Questions