-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
192 lines (173 loc) · 4.26 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
console.log("Script loaded!");
// Smooth scrolling for navigation links
const navLinks = document.querySelectorAll("nav ul li a");
navLinks.forEach((link) => {
link.addEventListener("click", (e) => {
e.preventDefault();
const targetId = link.getAttribute("href").substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
targetSection.scrollIntoView({
behavior: "smooth",
block: "start",
});
}
});
});
// GSAP Animations
gsap.registerPlugin(ScrollTrigger);
// Navbar slide-in animation
gsap.from("nav", {
y: -100,
duration: 1,
opacity: 0,
ease: "power4.out",
});
// Hero Section Animations
gsap
.timeline()
.from(".hero-content h1", {
opacity: 0,
y: -50,
duration: 1,
ease: "power4.out",
})
.from(
".hero-content p",
{
opacity: 0,
y: 50,
duration: 1,
ease: "power4.out",
},
"-=0.5"
)
.from(
".cta-buttons .btn",
{
opacity: 0,
scale: 0.8,
stagger: 0.2,
duration: 1,
ease: "power4.out",
},
"-=0.5"
);
// Floating animation for hero heading
gsap.to(".hero-content h1", {
y: 10,
duration: 2,
repeat: -1,
yoyo: true,
ease: "sine.inOut",
});
// Profile picture hover effect
const profilePic = document.querySelector(".profile-pic");
profilePic.addEventListener("mouseenter", () => {
gsap.to(profilePic, {
scale: 1.1,
duration: 0.3,
boxShadow: "0 4px 15px rgba(88, 166, 255, 0.5)",
});
});
profilePic.addEventListener("mouseleave", () => {
gsap.to(profilePic, {
scale: 1,
duration: 0.3,
boxShadow: "none",
});
});
// About Section Animation
gsap.from(".about", {
scrollTrigger: ".about",
opacity: 0,
y: 100,
duration: 1,
ease: "power4.out",
});
// Skills Section Animation with Delays
gsap.from(".skills-container .skill", {
scrollTrigger: ".skills-container",
opacity: 0,
scale: 0.8,
duration: 0.8,
stagger: 0.2,
ease: "power4.out",
});
// Hover animation for skills
document.querySelectorAll(".skill").forEach((skill) => {
skill.addEventListener("mouseenter", () => {
gsap.to(skill, {
scale: 1.2,
duration: 0.2,
});
});
skill.addEventListener("mouseleave", () => {
gsap.to(skill, {
scale: 1,
duration: 0.2,
});
});
});
// Projects Section Animations
gsap.utils.toArray(".project").forEach((project, index) => {
gsap.from(project, {
scrollTrigger: project,
opacity: 0,
x: index % 2 === 0 ? -100 : 100,
duration: 1,
ease: "power4.out",
});
});
// Hover effect for project cards
document.querySelectorAll(".project").forEach((project) => {
project.addEventListener("mouseenter", () => {
gsap.to(project, {
scale: 1.05,
duration: 0.3,
ease: "power1.out",
});
});
project.addEventListener("mouseleave", () => {
gsap.to(project, {
scale: 1,
duration: 0.3,
ease: "power1.out",
});
});
});
// Modal Logic
const modal = document.getElementById("modal");
const modalImages = document.getElementById("modal-images");
const closeModalButton = document.querySelector(".close");
const toggleGalleryButtons = document.querySelectorAll(".toggle-gallery-btn");
// Function to Show Modal
function showModal(imagesHTML) {
modalImages.innerHTML = imagesHTML; // Populate modal with images
modal.style.display = "flex"; // Display modal
}
// Function to Close Modal
function closeModal() {
modal.style.display = "none"; // Hide modal
modalImages.innerHTML = ""; // Clear modal content
}
// Event Listener for Close Button
closeModalButton.addEventListener("click", closeModal);
// Event Listener for Clicking Outside Modal Content
window.addEventListener("click", (e) => {
if (e.target === modal) closeModal();
});
// Event Listener for "View Images" Buttons
toggleGalleryButtons.forEach((button) => {
button.addEventListener("click", () => {
const projectFolder = button.getAttribute("data-project");
const folderPath = `assets/images/${projectFolder}/`;
const imagesHTML = Array.from({ length: 5 }, (_, i) => {
const imgSrc = `${folderPath}SS${i + 1}.png`;
return `<img src="${imgSrc}" alt="Screenshot ${
i + 1
}" onerror="this.style.display='none'"/>`;
}).join("");
showModal(imagesHTML);
});
});