Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (58 loc) · 2.2 KB
/
Copy pathscript.js
File metadata and controls
64 lines (58 loc) · 2.2 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
// Smooth scroll behavior
document.addEventListener('DOMContentLoaded', () => {
// Add smooth scrolling to all links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// Add intersection observer for fade-in animations on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe all animated elements
document.querySelectorAll('.book-item, .project-item, .music-item').forEach(el => {
observer.observe(el);
});
// Add active state to navigation based on current page
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
document.querySelectorAll('.nav-link').forEach(link => {
if (link.getAttribute('href') === currentPage) {
link.classList.add('active');
}
});
// Optional: Add play functionality to music artwork
document.querySelectorAll('.music-artwork').forEach(artwork => {
artwork.addEventListener('click', () => {
const playButton = artwork.querySelector('.play-button');
if (playButton.textContent === '▶') {
playButton.textContent = '⏸';
} else {
playButton.textContent = '▶';
}
});
});
});
// Add parallax effect to decorative element
window.addEventListener('scroll', () => {
const decorative = document.querySelector('.decorative-element');
if (decorative) {
const scrolled = window.pageYOffset;
decorative.style.transform = `translate(${scrolled * 0.1}px, ${scrolled * 0.1}px)`;
}
});