0

Is it possible to scroll bottom when overflow-y:scroll and height:100vh.

css

#content {
  height: 100vh;
  overflow-y: scroll;
}

js

var content = document.getElementById('content');
window.scrollTo(0, content.scrollHeight);

codepen https://codepen.io/betchi/pen/zjBwgx

betchi
  • 81
  • 1
  • 5

2 Answers2

1

In your example you are scrolling the entire window. It looks like what you want to do is scroll the content and not the window like this:

content.scrollTo(0, content.scrollHeight);
Shahar
  • 2,269
  • 1
  • 27
  • 34
0

You need to use the property scrollTop of the element you want to scroll.

Change your function to this:

function canNotScroll(){
  var content = document.getElementById('content');
  content.scrollTop = content.scrollHeight;
}