Skip to content

Commit 9c4dd97

Browse files
authored
Merge pull request #93 from m-code12/Scroll_to_top
feat: Added scroll-to-top feature
2 parents ad04fa7 + 5bc2613 commit 9c4dd97

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

archive.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons|Roboto">
4949
<link rel="stylesheet" href="/materialjs/material.min.css" />
5050
<link rel="stylesheet" href="style.css" />
51+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
5152
<script defer src="/materialjs/material.min.js"></script>
5253
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
5354

@@ -148,6 +149,9 @@ <h3>2019</h3>
148149
</ul>
149150
</div>
150151
</div>
152+
153+
<button onclick="topFunction()" id="myBtn" title="Go to top"><i class="fa fa-angle-double-up" aria-hidden="true" style="color: black;font-weight: bolder;"></i></button>
154+
151155
<div class="mdl-cell mdl-cell--6-col">
152156
<div class="nwoc-repo-card">
153157
<img src="https://cdnjs.cloudflare.com/ajax/libs/octicons/8.0.0/svg/mark-github.svg"/>
@@ -1388,4 +1392,27 @@ <h3>Previous Sponsors</h3>
13881392
</main>
13891393
</div>
13901394
</body>
1395+
1396+
<script>
1397+
//Get the button
1398+
var mybutton = document.getElementById("myBtn");
1399+
1400+
// When the user scrolls down 20px from the top of the document, show the button
1401+
window.onscroll = function() {scrollFunction()};
1402+
1403+
function scrollFunction() {
1404+
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
1405+
mybutton.style.display = "block";
1406+
} else {
1407+
mybutton.style.display = "none";
1408+
}
1409+
}
1410+
1411+
// When the user clicks on the button, scroll to the top of the document
1412+
function topFunction() {
1413+
document.body.scrollTop = 0;
1414+
document.documentElement.scrollTop = 0;
1415+
}
1416+
</script>
1417+
13911418
</html>

index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
5757
<link rel="stylesheet" href="/materialjs/material.min.css" />
5858
<link rel="stylesheet" href="style.css" />
59+
5960
<script defer src="/materialjs/material.min.js"></script>
6061
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
6162

@@ -132,6 +133,8 @@
132133
</div>
133134
</div>
134135

136+
<button onclick="topFunction()" id="myBtn" title="Go to top"><i class="fa fa-angle-double-up p-1 font-weight-bold" aria-hidden="true" style="color: black;"></i></button>
137+
135138
<div class="nwoc-content">
136139
<a id="about"></a>
137140
<h3>About</h3>
@@ -520,6 +523,27 @@ <h4>Tell your friends about NWoC</h4>
520523

521524
}());
522525
</script>
526+
<script>
527+
//Get the button
528+
var mybutton = document.getElementById("myBtn");
529+
530+
// When the user scrolls down 20px from the top of the document, show the button
531+
window.onscroll = function() {scrollFunction()};
532+
533+
function scrollFunction() {
534+
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
535+
mybutton.style.display = "block";
536+
} else {
537+
mybutton.style.display = "none";
538+
}
539+
}
540+
541+
// When the user clicks on the button, scroll to the top of the document
542+
function topFunction() {
543+
document.body.scrollTop = 0;
544+
document.documentElement.scrollTop = 0;
545+
}
546+
</script>
523547

524548
<script src="https://cdnjs.cloudflare.com/ajax/libs/tilt.js/1.2.1/tilt.jquery.min.js"></script>
525549
<script>

projects.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons|Roboto">
4949
<link rel="stylesheet" href="/materialjs/material.min.css" />
5050
<link rel="stylesheet" href="style.css" />
51+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
5152
<script defer src="/materialjs/material.min.js"></script>
5253
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
5354

@@ -155,6 +156,9 @@ <h3>NWoC 2020 Projects</h3>
155156
</ul>
156157
</div>
157158
</div>
159+
160+
<button onclick="topFunction()" id="myBtn" title="Go to top"><i class="fa fa-angle-double-up" aria-hidden="true" style="color: black;font-weight: bolder;"></i></button>
161+
158162
<div class="mdl-cell mdl-cell--6-col">
159163
<div class="nwoc-repo-card">
160164
<img src="https://cdnjs.cloudflare.com/ajax/libs/octicons/8.0.0/svg/mark-github.svg"/>
@@ -683,4 +687,25 @@ <h3>NWoC 2020 Projects</h3>
683687
</main>
684688
</div>
685689
</body>
690+
<script>
691+
//Get the button
692+
var mybutton = document.getElementById("myBtn");
693+
694+
// When the user scrolls down 20px from the top of the document, show the button
695+
window.onscroll = function() {scrollFunction()};
696+
697+
function scrollFunction() {
698+
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
699+
mybutton.style.display = "block";
700+
} else {
701+
mybutton.style.display = "none";
702+
}
703+
}
704+
705+
// When the user clicks on the button, scroll to the top of the document
706+
function topFunction() {
707+
document.body.scrollTop = 0;
708+
document.documentElement.scrollTop = 0;
709+
}
710+
</script>
686711
</html>

style.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ body {
99
background-color: #cbeef8;
1010
}
1111

12+
html {
13+
scroll-behavior: smooth;
14+
}
15+
16+
#myBtn {
17+
display: none;
18+
position: fixed;
19+
bottom: 20px;
20+
right: 30px;
21+
z-index: 99;
22+
font-size: 25px;
23+
border: none;
24+
outline: none;
25+
background-color: #87CEFA;
26+
color: white;
27+
font-color: blue;
28+
cursor: pointer;
29+
padding: 6px;
30+
border-radius: 50%;
31+
height: 50px;
32+
width: 50px;
33+
}
34+
35+
.fa-angle-double-up {
36+
font-weight: bolder;
37+
}
38+
39+
#myBtn:hover {
40+
background-color: #D3D3D3;
41+
}
42+
1243
p {
1344
font-size: 16px;
1445
}
@@ -102,6 +133,13 @@ a {
102133
}
103134
}
104135

136+
@media screen and (max-width: 961px) {
137+
#myBtn {
138+
bottom: 38px;
139+
right: 20px;
140+
}
141+
}
142+
105143
@media screen and (max-width: 960px) {
106144
.mdl-layout__header-row {
107145
padding: 0 10px 0 20px;

0 commit comments

Comments
 (0)