Ajax Address remain Scroll Position
I am using the jquery.address plugin to dynamically load my #content using Ajax. I also am using some effects for loading the new #content (i.e the old #content flies out, the new comes in from top, or from the side etc.) but I think that's not the开发者_运维百科 problem..
Problem is, that after the ajax request, the scroll position does not remain and the page jumps back to the top.
Is there any plugin/soultion on that? I read that storing the current position in a cookie and using $("html,body").animate({ scrollTop: x }, t); would help. But isn't there a better maybe more simpler way to accomplish that?
Thanks beforehand!
Mike
EDIT
Solved: Found out the solution is (comment out .focus()):
// Selects the proper navigation link
$('#menu a').each(function() {
//console.log($(this).attr('href'));
if (($(this).attr('href') == ($.address.state() + event.path)) {
//$(this).addClass('selected').focus(); // .focus() needs to be commented out in order to prevent to set the focus back to this class
$(this).addClass('selected');
}
else {
$('#menu ul li').removeClass('current-menu-item');
$(this).removeClass('selected');
}
});
This has to do with IE, mine does the same thing but works correctly in firefox. AFAIK saving the position and using scrollTop
like you did, could be the only workarround for IE.
精彩评论