-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathscrollEffect.js
73 lines (60 loc) · 1.94 KB
/
scrollEffect.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const cards = document.querySelectorAll(".card");
const Options = {
thresold: 1,
rootMargin: "0px 0px -150px 0px",
};
const animationAppear = new IntersectionObserver(function (
entries,
animationOnAppear
) {
entries.forEach((entry) => {
if (!entry.isIntersecting) {
return;
} else {
entry.target.classList.add("appear");
animationOnAppear.unobserve(entry.target);
}
});
},
Options);
cards.forEach((card) => {
animationAppear.observe(card);
});
let calcScrollValue = () => {
let scrollProgressup = document.getElementById("progressup");
let scrollProgressdown = document.getElementById("progressdown");
let pos = document.documentElement.scrollTop;
let calcHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
let scrollValue = Math.round((pos * 100) / calcHeight);
if (pos > 0) {
scrollProgressup.style.display = "grid";
scrollProgressup.style.background = `conic-gradient(#03cc65 ${scrollValue}%, #d7d7d7 ${scrollValue}%)`;
} else {
scrollProgressup.style.display = "none";
}
if (pos < calcHeight - window.innerHeight) {
scrollProgressdown.style.display = "grid";
scrollProgressdown.style.background = `conic-gradient(#03cc65 ${scrollValue}%, #d7d7d7 ${scrollValue}%)`;
} else {
scrollProgressdown.style.display = "none";
}
};
let scrollToTop = () => {
document.documentElement.scrollTop = 0;
};
let scrollToBottom = () => {
let scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
document.documentElement.scrollTop = scrollHeight;
};
let scrollProgressup = document.getElementById("progressup");
let scrollProgressdown = document.getElementById("progressdown");
scrollProgressup.addEventListener("click", scrollToTop);
scrollProgressdown.addEventListener("click", scrollToBottom);
window.onscroll = () => {
requestAnimationFrame(calcScrollValue);
};
window.onload = calcScrollValue;