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

Added a scroll to top button to the homepage #1236

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
11 changes: 11 additions & 0 deletions commonStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,14 @@ footer {
text-align: center;
}
}


#bttbutton{
position: fixed;
bottom: 20px;
right: 40px;
z-index: 9999;
border: none;
outline: none;
width: 55px;
}
3 changes: 3 additions & 0 deletions image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ <h1 class="text-indigo-600 text-center mb-10 uppercase font-semibold">
<!-- NewsLetter -->
<div
class="mt-8 newsLetter text-slate-300 flex text-xs flex-col justify-center lg:flex-row lg:justify-between items-center">
<!-- Scroll to top -->
<div class="md:pr-8">

<button id="bttbutton" title="backtotop">
<img src="image.svg" class="w-6 md:w-10 md:object-left"/>
</button>

</div>
<!-- Scroll to top -->

<div class="mb-1 text-center lg:text-left w-1/2">
<p class="capitalize text-[11px] font-semibold tracking-wider">Sign Up for our newsletter:</p>
Expand Down Expand Up @@ -617,7 +626,7 @@ <h1 class="text-3xl projectName">Moksh</h1>

</div>
</div>

<script src="./scrollUp.js"></script>
<script src="./script.js"></script>
<!-- Copyright Year js file -->
<script src="./copyrightYear.js"></script>
Expand Down
20 changes: 20 additions & 0 deletions scrollUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const topButton = document.getElementById("bttbutton");
const contentWrapper = document.querySelector(".contentWrapper");

function scrollUp() {
if (contentWrapper.scrollTop > 100) {
topButton.style.display = "block";
} else {
topButton.style.display = "none";
}
}

function getTop() {
contentWrapper.scrollTo({
top: 0,
behavior: "smooth",
});
}

contentWrapper.addEventListener("scroll", scrollUp);
topButton.addEventListener("click", getTop);
Loading