Skip to content

Commit cd375cf

Browse files
authored
bottom to top functionality added (#556)
1 parent 1d4dc3b commit cd375cf

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

index.html

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@
5555
background-color: #0056b3; /* Change this to your desired active background color */
5656
border-radius: 4px;
5757
}
58+
#back-to-top {
59+
position: fixed;
60+
bottom: 20px;
61+
right: 20px;
62+
display: none;
63+
background-color: #007bff;
64+
color: white;
65+
border: none;
66+
padding: 10px;
67+
border-radius: 50%;
68+
font-size: 18px;
69+
cursor: pointer;
70+
}
71+
#back-to-top:hover {
72+
background-color: #0056b3;
73+
}
5874
</style>
5975
</head>
6076

@@ -272,7 +288,7 @@ <h2 class="card-title">How to Create a GitHub Account</h2>
272288
</div>
273289
</div>
274290
</div>
275-
291+
<button id="back-to-top"><i class="fa fa-chevron-up"></i></button>
276292
<!-- Site footer -->
277293
<footer class="site-footer">
278294
<div class="container">
@@ -393,6 +409,23 @@ <h6>Quick Links</h6>
393409
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
394410
<script src="./ScrollToTop.js"></script>
395411
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
412+
<script>
413+
const backToTopButton = document.getElementById('back-to-top');
414+
window.addEventListener('scroll', () => {
415+
if (window.scrollY > 300) {
416+
backToTopButton.style.display = 'block';
417+
} else {
418+
backToTopButton.style.display = 'none';
419+
}
420+
});
421+
422+
backToTopButton.addEventListener('click', () => {
423+
window.scrollTo({
424+
top: 0,
425+
behavior: 'smooth'
426+
});
427+
});
428+
</script>
396429
<script>
397430
document.addEventListener('DOMContentLoaded', function () {
398431
fetch('data.json')
@@ -426,3 +459,5 @@ <h2 class="card-title">${post.title}</h2>
426459
</body>
427460

428461
</html>
462+
463+

0 commit comments

Comments
 (0)