blob: b7a6fa043465cbbb0789e2fa91cff496823ebd11 (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
document.addEventListener('scroll', function () {
progress();
hideSidebar();
});
function progress() {
const sections = document.getElementsByTagName("section");
const nodes = document.getElementsByTagName("nodes");
if (nodes[0]) {
for (var i = 0; i < sections.length; i++) {
if (isInViewport(sections[i])) {
nodes[i].style.width = "20px";
nodes[i].style.height = "20px";
}
else {
nodes[i].style.width = "10px";
nodes[i].style.height = "10px";
}
}
}
}
function hideSidebar() {
const sidebar = document.getElementById("sidebar");
const progressContainer = document.getElementById("progressContainer");
const sections = document.getElementsByTagName("section");
if (screen.width <= 600) {
if (window.scrollY >= 100) {
sidebar.style.left = "-80px";
for (var i = 0; i < sections.length; i++) {
sections[i].style.marginLeft = 0;
}
if (progressContainer) {
progressContainer.style.left = "-11px";
}
}
else {
sidebar.style.left = "0";
for (var i = 0; i < sections.length; i++) {
sections[i].style.marginLeft = "70px";
}
if (progressContainer) {
progressContainer.style.left = "61px";
}
}
}
else {
sidebar.style.left = "0";
progressContainer.style.left = "61px";
}
}
function isInViewport(element) {
const rect = element.getBoundingClientRect();
const visibleHeight = Math.min(rect.bottom, window.innerHeight) - Math.max(rect.top, 0);
const visibleWidth = Math.min(rect.right, window.innerWidth) - Math.max(rect.left, 0);
const elementHeight = rect.height;
const elementWidth = rect.width;
const halfElementHeight = elementHeight / 2;
const halfElementWidth = elementWidth / 2;
return (
visibleHeight >= halfElementHeight &&
visibleWidth >= halfElementWidth
);
}
|