File size: 931 Bytes
72f684c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var autoScrollBottom = true;

function updateScroll(){
    if (autoScrollBottom) {
        var element = document.getElementsByClassName("cm-scroller")[0];
        element.scrollTop = element.scrollHeight;
    }
}
function handleScroll() {
    var element = document.getElementsByClassName("cm-scroller")[0];
    //if (element.scrollHeight - element.scrollTop === element.clientHeight) {
    if (element.scrollHeight - (element.scrollTop + element.clientHeight) < 0.2*(element.scrollTop)) {
        // User has scrolled to the bottom, enable auto-scrolling
        autoScrollBottom = true;
        console.log("bottom");
    } else {
        console.log("not bottom");
        // User has scrolled away from the bottom, disable auto-scrolling
        autoScrollBottom = false;
    }
}
setInterval(updateScroll, 50);
var element = document.getElementsByClassName("cm-scroller")[0];
element.addEventListener("scroll", handleScroll);