-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from MehekFatima/main
Add 'Scroll back to top' button
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
<!-- Links to cdns --> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/full.min.css" rel="stylesheet" type="text/css" /> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script> | ||
<script nomodule src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.js"></script> | ||
</head> | ||
<body class="bg-white"> | ||
<div class="navbar bg-base-100"> | ||
|
@@ -185,5 +187,34 @@ <h6 class="footer-title">KCA University</h6> | |
<a class="link link-hover" href="https://www.kcau.ac.ke/enquire-now/">Join KCA University</a> | ||
</nav> | ||
</footer> | ||
|
||
<!-- Scroll to Top Button --> | ||
<button id="scrollToTopBtn"> | ||
<ion-icon name="chevron-up-outline"></ion-icon> | ||
</button> | ||
|
||
<script> | ||
// Get the button | ||
let mybutton = document.getElementById("scrollToTopBtn"); | ||
|
||
// When the user scrolls down 20px from the top of the document, show the button | ||
window.onscroll = function() { | ||
scrollFunction(); | ||
}; | ||
|
||
function scrollFunction() { | ||
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | ||
mybutton.style.display = "block"; | ||
} else { | ||
mybutton.style.display = "none"; | ||
} | ||
} | ||
|
||
// When the user clicks on the button, scroll to the top of the document | ||
mybutton.addEventListener("click", function() { | ||
document.body.scrollTop = 0; | ||
document.documentElement.scrollTop = 0; | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters