I've got JQuery running and I'd like to use a scrollTop animation to move the window back near the top (about 240px, though somewhat variable) as the callback of an AJAX call that will replace a large chunk of HTML content on the page.
I'm using:
$("html, body").animate({ scrollTop: someNumericalVariable });
The problem I run into is that, when this code runs with no delay or timeout, the window will do a very small scrolling animation to a location that is nowhere near desired. When I add a some arbitrary delay (at least 1 to a few seconds), the window may or may not end up in the desired location, but the animation is hardly an animation (it acts more like 2 separate scrollTop calls - it will quickly jump upward, wait a second, then jump upward again to the correct spot).
When I run the code separately (not as the callback in the middle of a bunch of HTML rendering), the animation seems to work properly.
Any ideas? Thanks in advance.