user3391975 user3391975 - 4 months ago 7
Javascript Question

How to stay at pagebottom (with javascript) while loading other page sections above?

I will have a onepager with different sections. I want to start with the last section (bottom of the page)and do load the other sections content with AJAX after the last section has been loaded.

The window does not stay with the last section. After loading the other sections content it follows them up.
How could I stay on the last section as long as I do not start scrolling up?

Answer

Vanilla Javascript:

window.scrollTo(0,document.body.scrollHeight);

jQuery:

$(document).scrollTop($(document).height());

Call this whenever you require to auto-scroll to page bottom.

Comments