-
Notifications
You must be signed in to change notification settings - Fork 60
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 #122 from SurajPrakash24/scroll-to-top
Added scroll to top button
- Loading branch information
Showing
3 changed files
with
42 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- views/scrollToTop.ejs --> | ||
<div id="scrollTopBtn" class="scroll-top" onclick="scrollToTop()"> | ||
↑ | ||
</div> | ||
|
||
<script> | ||
// Show button when user scrolls down | ||
window.onscroll = function () { | ||
var scrollTopBtn = document.getElementById('scrollTopBtn'); | ||
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | ||
scrollTopBtn.style.display = 'block'; | ||
} else { | ||
scrollTopBtn.style.display = 'none'; | ||
} | ||
}; | ||
// Function to scroll to top | ||
function scrollToTop() { | ||
document.body.scrollTop = 0; | ||
document.documentElement.scrollTop = 0; | ||
} | ||
</script> | ||
|
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
<div class="container"> | ||
<%- include("../includes/flash.ejs")%> <%- body %> | ||
</div> | ||
<%- include('../includes/scrollToTop.ejs') %> | ||
<%- include("../includes/footer.ejs")%> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
|