-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
153 lines (136 loc) · 4.44 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
//navigation bar hamburger
const navigationBar = document.querySelector('.nav-large');
const hamburger = document.querySelector('.nav-toggle');
const navBackground = document.querySelector('.nav-overlay');
hamburger.addEventListener('click', () => {
navBackground.classList.toggle('active');
navigationBar.classList.toggle('active');
})
const links = document.querySelectorAll('.fade-in-link');
links.forEach(link => {
link.addEventListener('click', () => {
navBackground.classList.toggle('active');
navigationBar.classList.toggle('active');
})
})
//navigation bar fade in
gsap.from('.fade-in-link', {duration: 1, opacity: 0, delay: 1, stagger: 0.3})
//hero text
const animateFadeElements = document.querySelectorAll('.animate-fade');
window.onload = function() {
animateFadeElements.forEach(element => element.classList.add('fade-in'));
}
//Particles for background
const count = 30;
const particleBackgroundColors = ['#4fc0e8', 'lightblue', 'white'];
for (let i = 0; i < count; i ++) {
const container = document.querySelector('.animation-container');
//random particle position
const heightStart = gsap.utils.random(10, 50);
const widthStart = gsap.utils.random(0, 30);
const heightEnd = gsap.utils.random(0, 40);
const widthEnd = gsap.utils.random(80, 90);
createParticle(container, heightStart, widthStart, heightEnd, widthEnd)
}
//Particles for heading
const titles = document.querySelectorAll('h2');
titles.forEach(title => {
for (let j = 0; j < 10; j ++) {
const heightStart = gsap.utils.random(0, 0);
const widthStart = gsap.utils.random(40, 45);
const heightEnd = gsap.utils.random(1, 1);
let widthEnd = gsap.utils.random(45, 60);
createParticle(title, heightStart, widthStart, heightEnd, widthEnd)
}
})
//particle function
function createParticle(container, heightStart, widthStart, heightEnd, widthEnd) {
const particle = document.createElement('div');
particle.classList.add('particle');
//random color particle
particle.style.backgroundColor = particleBackgroundColors[Math.floor(gsap.utils.random(0, 3))];
gsap.set(particle, {
y: `${heightStart}vh`,
x: `${widthStart}vw`,
//random particle size
scale: gsap.utils.random(0.5, 1)
})
container.append(particle);
animateParticle(particle, heightStart, widthStart, heightEnd, widthEnd);
}
function animateParticle(particle, heightStart, widthStart, heightEnd, widthEnd) {
const timelineTrajectory = gsap.timeline({
repeat: -1,
defaults: {
//random speed
duration: gsap.utils.random(3, 5),
ease: "none"
}})
//trajectory of particle
timelineTrajectory
.to(particle, {x: `${widthEnd}vw`})
.to(particle, {y: `${heightEnd}vh`, duration: gsap.utils.random(1, 2)})
.to(particle, {x: `${widthStart}vw`})
.to(particle, {y: `${heightStart}vh`, duration: gsap.utils.random(1, 2)})
const timelineOpacity = gsap.timeline({
defaults: {
//random speed
duration: gsap.utils.random(2, 3),
delay: gsap.utils.random(0, 1)
}})
timelineOpacity
.to(particle, {opacity: 0, duration: 0.5, repeat: 1})
.to(particle, {opacity: 0.7, repeat: -1})
}
//fade page in when user scrolls
const sections = document.querySelectorAll("section");
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting){
entry.target.classList.toggle("fade-in");
observer.unobserve(entry.target);
} else {
return;
}
})
}, {
threshold: 0.2
})
sections.forEach(section => {
observer.observe(section)
})
// Animate articles in when user scrolls into viewport
gsap.from('.article', {
scrollTrigger: ".article",
duration: 1,
x: '-200%',
delay: 1,
stagger: 0.5
})
//animate about me section
gsap.from('.slide-left-about', {
scrollTrigger: ".slide-left-about",
duration: 1,
x: '250%',
delay: 1
})
gsap.from('.slide-right-about', {
scrollTrigger: ".slide-right-about",
duration: 1,
x: '-250%',
delay: 1.5
})
//animate contact section
gsap.from('form', {
scrollTrigger: 'form',
duration: 1,
x: '200%'
})
//animate project section
gsap.from('.project-card', {
scrollTrigger: ".project-card",
duration: 1,
x: '400%',
delay: 1,
stagger: 0.5
})