-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
169 lines (134 loc) · 4.32 KB
/
Copy pathscript.js
File metadata and controls
169 lines (134 loc) · 4.32 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// aos
AOS.init();
// navigation
function toggleMenu() {
const menu = document.getElementById('menu');
const menuToggle = document.getElementById('menuToggle');
// Check if the screen width is 767px or less
const isMobile = window.matchMedia("(max-width: 800px)").matches;
if (!isMobile) {
// If the screen width is greater than 767px, do nothing
return;
}
// Determine if the menu is open or closed
const isMenuOpen = window.getComputedStyle(menu).display === 'flex';
if (isMenuOpen) {
// Close menu with GSAP animation
gsap.to(menu, {
duration: 0.5,
height: 0,
ease: 'power2.in', // Smooth ease-in effect when closing
onComplete: () => {
menu.style.display = 'none'; // Hide menu after animation completes
}
});
menuToggle.innerHTML = '☰';
} else {
// Open menu with GSAP animation
menu.style.display = 'flex'; // Make sure it's visible before animating
gsap.fromTo(menu,
{ height: 0 },
{
duration: 0.8,
height: 'auto',
ease: 'elastic.out(1, 0.5)', // Bouncy opening effect
}
);
menuToggle.innerHTML = '✖';
}
}
function closeNav() {
const menu = document.getElementById('menu');
const menuToggle = document.getElementById('menuToggle');
// Check if the screen width is 767px or less
const isMobile = window.matchMedia("(max-width: 800px)").matches;
if (!isMobile) {
// If the screen width is greater than 767px, do nothing
return;
}
const isMenuOpen = window.getComputedStyle(menu).display === 'flex';
if (isMenuOpen) {
// Close menu with GSAP animation
gsap.to(menu, {
duration: 0.5,
height: 0,
ease: 'power2.in', // Smooth ease-in effect when closing
onComplete: () => {
menu.style.display = 'none'; // Hide menu after animation completes
}
});
menuToggle.innerHTML = '☰';
}
}
// timeline
(function() {
'use strict';
// define variables
var items = document.querySelectorAll(".timeline li");
// check if an element is in viewport
// http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
function callbackFunc() {
for (var i = 0; i < items.length; i++) {
if (isElementInViewport(items[i])) {
items[i].classList.add("in-view");
}
}
}
// listen for events
window.addEventListener("load", callbackFunc);
window.addEventListener("resize", callbackFunc);
window.addEventListener("scroll", callbackFunc);
})();
// portfolio
const cards = document.querySelectorAll('.card');
cards.forEach((card) => {
card.addEventListener('click', () => {
if (!card.hasAttribute('active')) {
updateActiveCard(card);
}
});
});
function updateActiveCard(activeCard) {
cards.forEach((card) => {
if (card === activeCard) {
card.setAttribute('active', '');
} else {
card.removeAttribute('active');
}
})
}
// skills
gsap.registerPlugin(ScrollTrigger);
const skills = [
{ selector: ".python", width: "95%" },
{ selector: ".cplus", width: "95%" },
{ selector: ".java", width: "75%" },
{ selector: ".sql", width: "60%" },
{ selector: ".react", width: "85%" },
{ selector: ".js", width: "80%" },
{ selector: ".node", width: "90%" }
];
skills.forEach(skill => {
gsap.fromTo(
skill.selector,
{ width: "0%" },
{
width: skill.width,
duration: 3,
scrollTrigger: {
trigger: skill.selector,
start: "top 80%",
toggleActions: "play none none reverse",
}
}
);
});