When creating a div that immediately scrolls to the bottom on overflow, how can I continuously monitor for overflow and trigger a function to automatically scroll to the bottom of the page?
I came across this script that scrolls to the bottom:
<script type="text/javascript">
var objDiv = document.getElementsByClassName('container')[0];
objDiv.scrollTop = objDiv.scrollHeight;
<script>
And also found this script that checks for overflow:
<script type="text/javascript">
function isOverflown(element) {
return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
}
</script>
But what's the best way to consistently detect when overflow happens? Additionally, after always being scrolled to the bottom, if I manually try to go back to the top, it automatically scrolls to the bottom again. How can I prevent this behavior?