Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Scroll back to top' button #18

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
20 changes: 20 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ body {
width: 80%;
}

#scrollToTopBtn {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #EF5B25;
color: white;
border: none;
width: 54px;
height: 54px;
padding: 0;
border-radius: 50%;
padding: 15px;
cursor: pointer;
display: none;
z-index: 1000;
}
#scrollToTopBtn ion-icon {
font-size: 24px;
}

/* media */
@media (max-width: 1200px) {
.mission .right p {
Expand Down