Auto Scroll with scrollTop()

Auto Scroll with scrollTop()

I am trying to make a page scroll to a certain point as soon as it loads. The endgame is actually to have it delay scrolling for 2 seconds and then use an animation to scroll to this point, but right now, I will be happy to just get the scrolling working at all.

Here are the two configurations I've tried.

  1. $(window).scrollTop($("#anchor").offset().top);

I have also tried "body", document, "html", "html, body", etc. where window is above, as well as many different selectors where the "#anchor" is. Some were created from the Wordpress template. Some I added myself, using different elements and selector types.

  1. $(window).animate({scrollTop: $("#anchor").offset().top}, 500, 'swing');

I've spent hours typing, retyping, and rearranging these two simple lines of code in completely unnecessary and redundant ways and reading what other people have to say to no avail. I've seen similar code to what I've written above working in jsfiddle without a problem. Other simple jquery works just fine on my own site, and when I include a completion function in the second example, it gets executed as if the entire thing worked. Also, with the second one, the window will actually scroll to the proper place then immediately scroll back up to the top of the page.

If I cannot get this to work, I will have to use CSS3, which, considering what I want to do, will not be backwards compatible in the least. So it is an undesirable solution.