Skip to content

Commit 7a6efed

Browse files
committed
11-Back to Top
1 parent 3ca469a commit 7a6efed

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ <h4>Follow Us</h4>
244244
</p>
245245
</div>
246246
</footer>
247-
<div class="hidden">
248-
<a href="">
247+
<div class="fixed z-30 bottom-0 right-0 mr-6 mb-6">
248+
<a id="back2Top" href="#" class="hidden text-white bg-red-800 bg-opacity-50 rounded-md">
249249
<span class="hidden">Back to Top</span>
250250
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 24 24" class="h-10 w-10">
251251
<path fill="currentColor" d="M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z" />

public/js/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const nav = document.querySelector('#mainNav');
22
const mobileMenu = document.querySelector('#mobileMenu');
33
const mobileMenuIcons = mobileMenu.querySelectorAll('svg');
44
const mainMenu = document.querySelector('#mainMenu');
5+
const back2Top = document.querySelector('#back2Top');
56

67
//functions
78
function toggleBurger() {
@@ -25,3 +26,8 @@ mobileMenu.addEventListener('click', (e) => {
2526

2627
toggleBurger();
2728
});
29+
30+
back2Top.addEventListener('click', (e) => {
31+
e.preventDefault();
32+
window.scroll({ top: 0, left: 0, behavior: 'smooth' });
33+
});

0 commit comments

Comments
 (0)