Skip to content

Commit 1b789e9

Browse files
Add Floating button to reach to top of page
1 parent 9d22b2c commit 1b789e9

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

assests/images/upicon.png

37.7 KB
Loading

index.html

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<link rel="stylesheet" href="styles.css" />
99
<link rel="icon" href="./icons/icon.png" />
1010
<link href="https://cdn.jsdelivr.net/npm/[email protected]/fonts/remixicon.css" rel="stylesheet" />
11+
<script src="https://kit.fontawesome.com/9ce43fc1dc.js" crossorigin="anonymous"></script>
1112
<link rel="preconnect" href="https://fonts.googleapis.com" />
1213
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1314
<link
@@ -238,6 +239,14 @@ <h2>Spell of the Day</h2>
238239
</div>
239240
</div>
240241

242+
<!-- FAB -->
243+
<a href="#top" class = "to-top">
244+
245+
<img src="assests/images/upicon.png" alt="Hogwarts Clipart" style="width: 60px; height: 60px; filter: brightness(90%);">
246+
<i class="fa-solid fa-arrow-up"></i>
247+
248+
</a>
249+
241250
<!-- Footer Section -->
242251
<footer class="footer">
243252
<div class="footer-top">

script.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,18 @@ document.addEventListener('DOMContentLoaded', function() {
409409
backgroundSound.play();
410410
backgroundSound.loop = true;
411411
});
412-
});
412+
});
413+
414+
//fab
415+
416+
var toTop = document.querySelector('.to-top');
417+
418+
window.addEventListener('scroll', function() {
419+
if(window.pageYOffset > 100) {
420+
toTop.classList.add("active");
421+
}
422+
else
423+
{
424+
toTop.classList.remove("active")
425+
}
426+
});

styles.css

+36
Original file line numberDiff line numberDiff line change
@@ -602,3 +602,39 @@ button:disabled {
602602
padding: 10px;
603603
}
604604
}
605+
606+
/*FAB
607+
*/
608+
.to-top {
609+
z-index: 10;
610+
position: fixed;
611+
bottom: 20px;
612+
right: 20px;
613+
pointer-events: none;
614+
border:#1f1f1f;
615+
width: auto;
616+
height:auto;
617+
color: whitesmoke;
618+
display:flex;
619+
align-items: center;
620+
justify-content: center;
621+
font-size: 32px;
622+
text-decoration: none;
623+
opacity: 0;
624+
transition: all .4s;
625+
}
626+
627+
.to-top img {
628+
display : block;
629+
}
630+
.to-top .fa-arrow-up {
631+
position: absolute;
632+
633+
}
634+
635+
.to-top.active {
636+
637+
cursor: pointer;
638+
pointer-events: auto;
639+
opacity:1
640+
}

0 commit comments

Comments
 (0)