Ask Your Question
1

How can the bottom of a div be automatically scrolled to when it is launched?

asked 2023-06-15 07:21:04 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-15 07:46:02 +0000

bukephalos gravatar image

One possible solution is to use JavaScript to set the "scrollTop" property of the div element to its maximum height when the page is loaded. Here's an example:

HTML:

<div id="myDiv">Content</div>

JavaScript:

window.onload = function() {
  var myDiv = document.getElementById("myDiv");
  myDiv.scrollTop = myDiv.scrollHeight;
}

This code retrieves the "myDiv" element using its ID, then sets its "scrollTop" property to its maximum height, which is the same as its "scrollHeight" property. This will automatically scroll the bottom of the div into view when the page is loaded.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-15 07:21:04 +0000

Seen: 11 times

Last updated: Jun 15 '23