-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscrollbar.txt
More file actions
114 lines (98 loc) · 2.25 KB
/
Copy pathscrollbar.txt
File metadata and controls
114 lines (98 loc) · 2.25 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// html
<div class="progress-container">
<div id="progressbar" class="progress-bar"></div>
</div>
<div class="wrapper">
<section>
<h2>Scroll down</h2>
</section>
<section>
<h2>...keep going...</h2>
</section>
<section>
<h2>Almost there...</h2>
</section>
<section>
<h2>I can't believe you've done this.</h2>
<br>
<br>
<img src="https://i1.sndcdn.com/artworks-000153836556-yyqn60-t500x500.jpg" alt="">
</section>
</div>
// css
@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Roboto:wght@100;300&display=swap");
body {
background-color: #333;
font-family: "Press Start 2P", cursive;
margin: 0;
padding: 0;
-ms-overflow-style: none; /* for Internet Explorer, Edge */
scrollbar-width: none; /* for Firefox */
overflow-y: scroll;
}
body::-webkit-scrollbar {
display: none; /* for Chrome, Safari, and Opera */
}
.header h2 {
text-align: center;
}
.progress-container {
position: fixed;
right: 10px;
width: 8px;
height: 90%;
background: #222;
border-radius: 2px;
margin: auto;
}
.progress-bar {
width: 8px;
background: #d4b255;
border-radius: 2px;
}
.progress-bar:before {
height: 1%;
}
.glow {
-webkit-box-shadow: 0px 0px 14px 21px rgba(212, 178, 85, 0.48);
-moz-box-shadow: 0px 0px 14px 21px rgba(212, 178, 85, 0.48);
box-shadow: 0px 0px 14px 21px rgba(212, 178, 85, 0.48);
}
.wrapper {
margin-top: 10px;
margin-bottom: 10px;
}
section {
height: 100vh;
text-align: center;
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
align-content: center;
}
h2 {
color: #f1f1f1;
}
img {
width: 20%;
}
// js
const progressBar = document.getElementById("progressbar");
progressBar.style.height = 1 + "%";
window.onscroll = () => {
const scroll = document.documentElement.scrollTop;
const height =
document.documentElement.scrollHeight - document.documentElement.clientHeight;
let scrolled = (scroll / height) * 100;
if (scrolled <= 1) {
progressBar.style.height = 1 + "%";
} else if (scrolled >= 2 && scrolled <= 99.9) {
progressBar.style.height = scrolled + "%";
progressBar.classList.remove("glow");
} else if (scrolled === 100) {
progressBar.style.height = scrolled + "%";
// Do something when reached 100% scroll
progressBar.classList.add("glow");
}
};