Skip to content

Commit 6b98dd2

Browse files
authored
Update script.js
1 parent 6e384a4 commit 6b98dd2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

script.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
// Mobile nav toggle
2+
const navToggle = document.querySelector('.nav-toggle');
3+
const navMenu = document.querySelector('.nav');
4+
5+
navToggle.addEventListener('click', () => {
6+
navMenu.classList.toggle('visible');
7+
});
8+
9+
// Back to top button
10+
const topBtn = document.getElementById('topBtn');
11+
window.onscroll = function() {
12+
topBtn.style.display = (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) ? 'flex' : 'none';
13+
};
14+
15+
topBtn.addEventListener('click', () => {
16+
window.scrollTo({ top: 0, behavior: 'smooth' });
17+
});
18+
119
// Simple selectors
220
const q = (s, p=document) => p.querySelector(s);
321
const qAll = (s, p=document) => Array.from(p.querySelectorAll(s));
@@ -102,3 +120,4 @@ try {
102120
document.addEventListener('keydown', (e) => {
103121
if (e.key === 'Tab') document.body.classList.add('show-focus');
104122
});
123+

0 commit comments

Comments
 (0)