-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
149 lines (127 loc) · 3.49 KB
/
index.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
// Fix Nav
const navBar = document.querySelector(".nav");
const navHeight = navBar.getBoundingClientRect().height;
window.addEventListener("scroll", () => {
const scrollHeight = window.scrollY;
if (scrollHeight > navHeight) {
navBar.classList.add("fix-nav");
} else {
navBar.classList.remove("fix-nav");
}
});
// Smooth Scroll Function
function smoothScroll(target, duration) {
const targetElement = document.querySelector(target);
const targetPosition = targetElement.getBoundingClientRect().top + window.scrollY;
const startPosition = window.scrollY;
const distance = targetPosition - startPosition;
let startTime = null;
function animation(currentTime) {
if (startTime === null) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const run = ease(timeElapsed, startPosition, distance, duration);
window.scrollTo(0, run);
if (timeElapsed < duration) requestAnimationFrame(animation);
}
function ease(t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t + b;
t--;
return -c / 2 * (t * (t - 2) - 1) + b;
}
requestAnimationFrame(animation);
}
// Smooth Scroll for Anchor Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = this.getAttribute('href');
smoothScroll(target, 100); // Adjust duration as needed
});
});
// Toggle Menu
const menu = document.querySelector(".menu");
const navOpen = document.querySelector(".hamburger");
const navClose = document.querySelector(".close");
const navLeft = menu.getBoundingClientRect().left;
navOpen.addEventListener("click", () => {
if (navLeft < 0) {
menu.classList.add("show");
document.body.classList.add("show");
navBar.classList.add("show");
}
});
navClose.addEventListener("click", () => {
if (navLeft < 0) {
menu.classList.remove("show");
document.body.classList.remove("show");
navBar.classList.remove("show");
}
});
// Glidejs
const glide = document.querySelector(".glide");
if (glide)
new Glide(glide, {
type: "carousel",
startAt: 0,
perView: 3,
gap: 30,
hoverpause: true,
autoplay: 2000,
animationDuration: 800,
animationTimingFunc: "linear",
breakpoints: {
996: {
perView: 2,
},
768: {
perView: 1,
},
},
}).mount();
AOS.init();
new TypeIt("#type1", {
speed: 120,
loop: true,
waitUntilVisible: true,
})
.type("Developer", { delay: 400 })
.pause(500)
.delete(9)
.type("Computer Engineer", { delay: 400 })
.pause(400)
.delete(18)
.go();
new TypeIt("#type2", {
speed: 120,
loop: true,
waitUntilVisible: true,
})
.type("Developer", { delay: 400 })
.pause(500)
.delete(9)
.type("Computer Engineer", { delay: 400 })
.pause(500)
.delete(18)
.go();
gsap.from(".logo", { opacity: 0, duration: 1, delay: 0.5, y: -10 });
gsap.from(".hamburger", { opacity: 0, duration: 1, delay: 0.8, x: 20 });
gsap.from(".banner", { opacity: 0, duration: 1, delay: 1.1, x: -200 });
gsap.from(".hero h3", { opacity: 0, duration: 1, delay: 1.4, y: -50 });
gsap.from(".hero h1", { opacity: 0, duration: 1, delay: 1.7, y: -45 });
gsap.from(".hero h4", { opacity: 0, duration: 1, delay: 2.1, y: -30 });
gsap.from(".hero a", { opacity: 0, duration: 1, delay: 2.4, y: -10 });
gsap.from(".nav-item", {
opacity: 0,
duration: 1,
delay: 1,
y: 30,
stagger: 0.2,
});
gsap.from(".icons span", {
opacity: 0,
duration: 1,
delay: 2.5,
x: -30,
stagger: 0.2,
});