Doodled Doodled - 2 months ago 11
jQuery Question

Jquery scroll slowly to h1 tag minus 100 pixels on page load

I have a number of pages where I want the user to be aware there is content above the h1 tag (a search box) but not have to scroll past it every time to get to the content.

I know how to do a clickable link that will fire JQuery to scroll the page down to a specific id but I can't seem to find any way to:
1) scroll down on page load.
2) scroll to h1 rather than an element id.

Is it possible?

Cheers

Ish Ish
Answer

Try this:

$(document).ready(function() {
    $('html,body').animate({
        scrollTop: $('h1:first').offset().top
    }, 800, function() {
    });
});
Comments