-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
111 lines (99 loc) · 3.94 KB
/
script.js
File metadata and controls
111 lines (99 loc) · 3.94 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function toggleMenu() {
const menuLinks = document.querySelector('.menu-links');
const hamburgerIcon = document.querySelector('.hamburger-icon');
menuLinks.classList.toggle('open');
hamburgerIcon.classList.toggle('open');
}
window.addEventListener('scroll', function () {
const menuLinks = document.querySelector('.menu-links');
const hamburgerIcon = document.querySelector('.hamburger-icon');
if (window.scrollY > 0 && menuLinks.classList.contains('open')) {
menuLinks.classList.remove('open');
hamburgerIcon.classList.remove('open');
}
});
// Add loading class to prevent smooth scrolling on page load
document.documentElement.classList.add('loading');
// Reset scroll position when page loads
window.onload = function() {
window.scrollTo(0, 0);
// Remove loading class after scroll reset
document.documentElement.classList.remove('loading');
};
// Scroll Animation
document.addEventListener('DOMContentLoaded', function() {
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
let isScrolling = false;
let scrollTimeout;
// Add scroll event listener to detect fast scrolling
window.addEventListener('scroll', function() {
isScrolling = true;
clearTimeout(scrollTimeout);
// Reset isScrolling after scrolling stops
scrollTimeout = setTimeout(function() {
isScrolling = false;
}, 150);
});
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// If we're scrolling quickly, apply animations immediately without delays
if (isScrolling) {
entry.target.style.transitionDelay = '0s';
}
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Add animation classes to elements
const sections = document.querySelectorAll('section');
sections.forEach(section => {
// Profile section
if (section.id === 'profile') {
section.querySelector('.section__pic-container').classList.add('slide-in-left');
section.querySelector('.section__text').classList.add('slide-in-right');
}
// About section
else if (section.id === 'about') {
section.querySelector('.about-details-container').classList.add('fade-in');
const skillItems = section.querySelectorAll('.skill-item');
skillItems.forEach((item, index) => {
item.classList.add('scale-in');
// Only apply delay if not scrolling quickly
if (!isScrolling) {
item.style.transitionDelay = `${index * 0.05}s`;
}
});
}
// Projects section
else if (section.id === 'projects') {
const projectCards = section.querySelectorAll('.project-card');
projectCards.forEach((card, index) => {
card.classList.add('fade-in');
// Only apply delay if not scrolling quickly
if (!isScrolling) {
card.style.transitionDelay = `${index * 0.2}s`;
}
});
}
// Contact section
else if (section.id === 'contact') {
const contactContainers = section.querySelectorAll('.contact-info-container');
contactContainers.forEach((container, index) => {
container.classList.add('slide-in-left');
// Only apply delay if not scrolling quickly
if (!isScrolling) {
container.style.transitionDelay = `${index * 0.2}s`;
}
});
}
});
// Observe all animated elements
document.querySelectorAll('.fade-in, .slide-in-left, .slide-in-right, .scale-in').forEach(element => {
observer.observe(element);
});
});