I am trying to create a website using JavaScript. I need to programm it in such a way, that when you open the website, you directly get to the bottom of the page (without clicking anything). That means, the page moves itself automatically downwards. How can I get this done?
Asked
Active
Viewed 76 times
0
-
1Possible duplicate of [Scroll Automatically to the Bottom of the Page](https://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) – jkp May 28 '17 at 11:40
2 Answers
0
Use window.scrollTo()
function
window.scrollTo(0,document.body.scrollHeight);
![](../../users/profiles/2834937.webp)
Dinesh undefined
- 5,216
- 2
- 14
- 37
0
Here's a good answer: how to automatically scroll down a html page?
Including a live demo: http://jsfiddle.net/ThinkingStiff/DG8yR/
Script:
function top() {
document.getElementById( 'top' ).scrollIntoView();
};
function bottom() {
document.getElementById( 'bottom' ).scrollIntoView();
window.setTimeout( function () { top(); }, 2000 );
};
bottom();
Html:
<div id="top">top</div>
<div id="bottom">bottom</div>
CSS:
#top {
border: 1px solid black;
height: 3000px;
}
#bottom {
border: 1px solid red;
}
Enjoy :)
![](../../users/profiles/1502265.webp)
Guy Segev
- 1,489
- 14
- 21