-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
81 lines (72 loc) · 2.5 KB
/
Copy pathscript.js
File metadata and controls
81 lines (72 loc) · 2.5 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function() {
if (localStorage.getItem('th') === 'dark') { document.body.classList.add('dark'); }
var themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', function() {
document.body.classList.toggle('dark');
localStorage.setItem('th', document.body.classList.contains('dark') ? 'dark' : '');
});
}
var nav = document.getElementById('main-nav');
if (nav) {
window.addEventListener('scroll', function() {
var currentScroll = window.scrollY || 0;
if (currentScroll < 100) {
nav.style.transform = 'translate(-50%, 0)';
nav.style.opacity = '1';
nav.style.pointerEvents = '';
} else {
nav.style.transform = 'translate(-50%, -120px)';
nav.style.opacity = '0';
nav.style.pointerEvents = 'none';
}
}, { passive: true });
}
var backToTop = document.getElementById('back-to-top');
if (backToTop) {
function updateBackToTop() {
if (window.scrollY > 200) {
backToTop.classList.add('visible');
} else {
backToTop.classList.remove('visible');
}
}
window.addEventListener('scroll', updateBackToTop, { passive: true });
updateBackToTop();
backToTop.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}
document.querySelectorAll('.nav-link').forEach(function(link) {
e.preventDefault();
var target = document.querySelector(link.getAttribute('href'));
if (!target) return;
var start = window.scrollY || 0;
var end = target.getBoundingClientRect().top + start - 100;
var dist = end - start;
var dur = 600;
var startTime = null;
function step(now) {
if (!startTime) startTime = now;
var t = Math.min((now - startTime) / dur, 1);
var ease = t < .5 ? 2*t*t : -1+(4-2*t)*t;
window.scrollTo(0, start + dist*ease);
if (t < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
});
var footer = document.querySelector('.contact-footer');
if (footer) {
var lastScroll = window.scrollY || 0;
window.addEventListener('scroll', function() {
var currentScroll = window.scrollY || 0;
var scrollDirection = currentScroll > lastScroll ? 'down' : 'up';
if (scrollDirection === 'up' && currentScroll > 0) {
footer.classList.add('visible');
} else {
footer.classList.remove('visible');
}
lastScroll = currentScroll;
}, { passive: true });
}
})();