3

I have got a div with Overflow-y. When the text becomes to large it is possible to scroll to the bottom half of the text.

My question is: How do I let it start at the bottom half of the div and not at the top half? So that you will view the bottom half of the text first.

This is the CSS used for the div.

#Middle{
margin: 0px;
padding: 0px;
width: 234px;
height: 287px;
margin-left: auto;
margin-right: auto;
margin-top: 7px;
padding: 5px;
background-color: #F0F0F0;
overflow-y: scroll;
resize: none;
box-shadow:inset 0 0 5px #000000;
-moz-box-shadow:inset 0 0 5px #000000;
-webkit-box-shadow:0 0 5px #000000;
}

I just add this right? Because it won't work. (sorry I'm not experienced with JavaScript yet)

<head><script>
var div = document.getElementById("Middle");
div.scrollTop = div.scrollHeight;
</script></head>
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
MHarteveld
  • 167
  • 2
  • 8

3 Answers3

0

apparently there is a question same as yours with an accepted answer.

var objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;
Community
  • 1
  • 1
Dan Ovidiu Boncut
  • 3,083
  • 4
  • 25
  • 45
0

This usually works:

var div = document.getElementById("ID");
div.scrollTop = div.scrollHeight;
0

Your solution should work, you just need to put it on the end of the page so when you call document.getElementById the element already exists on the DOM.

Here is an working example:

<body>
  <div id="Middle">
    <!-- some long content -->
  </div>

  <script>
    var div = document.getElementById("Middle");
    div.scrollTop = div.scrollHeight;
  </script>
</body>
Moshe Simantov
  • 3,937
  • 2
  • 25
  • 35