aboutsummaryrefslogtreecommitdiff
path: root/public/assets/scroll.js
blob: a0c6b78583d55684d5511613a4fa84c720334335 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function posY(elm) {
    var test = elm, top = 0;

    while(!!test && test.tagName.toLowerCase() !== "body") {
        top += test.offsetTop;
        test = test.offsetParent;
    }

    return top;
}

function viewPortHeight() {
    var de = document.documentElement;

    if(!!window.innerWidth)
    { return window.innerHeight; }
    else if( de && !isNaN(de.clientHeight) )
    { return de.clientHeight; }

    return 0;
}

function scrollY() {
    if( window.pageYOffset ) { return window.pageYOffset; }
    return Math.max(document.documentElement.scrollTop, document.body.scrollTop);
}

function checkvisible( elm ) {
    var vpH = viewPortHeight(), // Viewport Height
        st = scrollY(), // Scroll Top
        y = posY(elm);

    return (y > (vpH + st));
}

document.body.innerHTML = document.body.innerHTML.replaceAll("\n", "").replace(/> *</gm, "><").trim();

window.onscroll = () => {
    if (window.innerWidth > 700) {
        if (window.scrollY() > (window.innerHeight - 52)) {
            document.getElementsByClassName("navbar")[0].classList.add("scrolled");
        } else {
            document.getElementsByClassName("navbar")[0].classList.remove("scrolled");
        }
    } else {
        if (window.scrollY() > (window.innerHeight - 120)) {
            document.getElementsByClassName("navbar")[0].classList.add("scrolled");
        } else {
            document.getElementsByClassName("navbar")[0].classList.remove("scrolled");
        }
    }
}