Tran
Tran

Reputation: 315

Auto scroll to a div after finish loading. Use jquery

I have a div with id=now, this div is empty and do not have any css property (no width, no height, just a hidden div). I want when browser finish load the page, then scroll to this div immediately. User do not need to click on some thing.

Here is my html

<html>
<div>Long div Lorem ipsum</div>
<div id="now"></div>
<div>Long div Lorem ipsum</div>

How to do this with jquery ?

Upvotes: 3

Views: 15518

Answers (1)

visualidiot
visualidiot

Reputation: 550

$(function() { // when the DOM is ready...
    //  Move the window's scrollTop to the offset position of #now
    $(window).scrollTop($('#now').offset().top);
});

Upvotes: 12

Related Questions