jquery - Animate scroll to ID on page load -



jquery - Animate scroll to ID on page load -

im tring animate scroll particular id on page load. have done lots of research , came across this:

$("html, body").animate({ scrolltop: $('#title1').height() }, 1000);

but seems start id , animate top of page?

the html (which half way downwards page) simply:

<h2 id="title1">title here</h2>

any suggestions?

adi

you scrolling height of element. offset() returns coordinates of element relative document, , top param give element's distance in pixels along y-axis:

$("html, body").animate({ scrolltop: $('#title1').offset().top }, 1000);

and can add together delay it:

$("html, body").delay(2000).animate({scrolltop: $('#title1').offset().top }, 2000);

jquery scroll jquery-animate

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -