Skip to content

Commit

Permalink
addgototopbtn
Browse files Browse the repository at this point in the history
  • Loading branch information
rahat2134 committed Jan 15, 2024
1 parent 65612fe commit 0cfa918
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,30 @@ <h4>Address</h4>
Copyright © 2023 Arpan Chowdhury. All rights reserved.
</div>
</footer>
<!-- adding a btn -->
<button id="goToTopBtn" onclick="goToTop()">Go to Top</button>
<script>
// Get the button
var mybutton = document.getElementById("goToTopBtn");

// 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
function goToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
</body>
</html>
19 changes: 18 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,21 @@ header {
.footer__container {
grid-template-columns: repeat(2, 1fr);
}
}
}
/* doing changes */
#goToTopBtn {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
background-color: #007bff;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}

#goToTopBtn:hover {
background-color: #0056b3;
}

0 comments on commit 0cfa918

Please sign in to comment.