-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
65 lines (57 loc) · 1.83 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Smooth scrolling to section anchors
const smoothScroll = function(target, duration) {
const targetElement = document.querySelector(target);
const targetPosition = targetElement.getBoundingClientRect().top;
const startPosition = window.pageYOffset;
const distance = targetPosition - startPosition;
let startTime = null;
const animation = function(currentTime) {
if (startTime === null) {
startTime = currentTime;
}
const timeElapsed = currentTime - startTime;
const run = ease(timeElapsed, startPosition, distance, duration);
window.scrollTo(0, run);
if (timeElapsed < duration) {
requestAnimationFrame(animation);
}
};
const ease = function(t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t + b;
t--;
return -c / 2 * (t * (t - 2) - 1) + b;
};
requestAnimationFrame(animation);
};
const links = document.querySelectorAll('nav a');
links.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const section = this.getAttribute('href');
smoothScroll(section, 1000);
});
});
// Show/hide mobile menu
const menuBtn = document.querySelector('.menu-btn');
const mobileNav = document.querySelector('nav ul');
let menuOpen = false;
menuBtn.addEventListener('click', function() {
if (!menuOpen) {
menuBtn.classList.add('open');
mobileNav.classList.add('open');
menuOpen = true;
} else {
menuBtn.classList.remove('open');
mobileNav.classList.remove('open');
menuOpen = false;
}
});
// Toggle project details
const projectBtns = document.querySelectorAll('.project-btn');
projectBtns.forEach(btn => {
btn.addEventListener('click', function() {
const projectDetails = this.nextElementSibling;
projectDetails.classList.toggle('open');
});
});