-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
243 lines (196 loc) · 5.89 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// #region | background zoom in and out on scroll
let bg = document.querySelector(".bg")
function bgZoom() {
let scroll = window.pageYOffset
bg.style.width = `${112 - scroll / 310}vw`
bg.style.height = `${112 - scroll / 310}vh`
bg.style.marginLeft = `-${(112 - scroll / 310) / 2}vw`
bg.style.marginTop = `-${(112 - scroll / 310) / 2}vh`
}
// #endregion
// #region | side-nav page indicators
const sections = document.querySelectorAll(".sec")
const sidenav = document.querySelector(".sidenav")
function updatePageIndicators() {
const link = document.querySelectorAll(".dot")
const top = window.pageYOffset
sections.forEach((each) => {
let id = each.getAttribute("id")
let height = each.clientHeight
let offset = each.getBoundingClientRect().top + window.scrollY - height + 150;
if (top >= offset && top < offset + height) {
link.forEach((e) => e.classList.remove("active"))
const finder = document.querySelector(`[data-scroll="${id}"]`)
finder.classList.add("active")
}
});
}
updatePageIndicators()
// #endregion
// #region | scroll to top arrow
const scrollArrow = document.querySelector(".scroll-arrow")
scrollArrow.addEventListener("click", () => {
window.scrollTo(0, 0)
})
function showScrollTopArrow() {
let current = window.innerHeight + window.scrollY
let bottom = document.body.scrollHeight
if (bottom - current < 650) {
scrollArrow.classList.add("show")
} else {
scrollArrow.classList.remove("show")
}
}
// #endregion
window.addEventListener("scroll", () => {
bgZoom()
updatePageIndicators()
showScrollTopArrow()
})
// #region | sections and bouncing letters
function createTitle(text, element) {
text = text.replaceAll(" ", "+").replaceAll("\n", "~")
// + for space and ~ for new line
const textArr = text.split("");
for (let i = 0; i < textArr.length; i++) {
setTimeout(() => {
const letter = document.createElement("h1");
if (textArr[i] === "+") {
letter.innerText = "\xa0"
element.append(letter)
} else if (textArr[i] === "~") {
const br = document.createElement("br")
element.append(br)
} else {
letter.innerText = textArr[i];
element.append(letter);
letter.classList.add("bounceIn");
setTimeout(() => {
letter.classList.remove("bounceIn");
}, 800)
letter.addEventListener("mouseenter", () => {
if (letter.classList.contains("animationRunning")) {
return
}
letter.classList.add("animationRunning");
letter.classList.add("rubberband");
setTimeout(() => {
letter.classList.remove("rubberband");
letter.classList.remove("animationRunning");
}, 600);
});
}
}, i * 60);
}
}
const homeTitle = document.querySelector(".home-title")
const homeDownloadResumeBtn = document.querySelector(".download-resume-btn")
setTimeout(() => {
createTitle("Hi,\nI'm Tamir,\nFull Stack Developer", homeTitle)
setTimeout(() => {
homeDownloadResumeBtn.classList.add("observer-animation")
}, 1000);
}, 1000);
const ioTargets = document.querySelectorAll(".section-title");
ioTargets.forEach(target => {
const io = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target
createTitle(entry.target.getAttribute("data-text"), entry.target)
observer.disconnect()
}
})
}, { threshold: 1 })
io.observe(target, { rootMargin: "100px" })
})
const contactFormElements = document.querySelectorAll("form input, form textarea, form button")
contactFormElements.forEach(target => {
const io = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target
el.classList.add("observer-animation")
observer.disconnect()
}
})
})
io.observe(target, { rootMargin: "-100px" })
})
let timeout = false
const nameInput = document.querySelector("#name-input")
const emailInput = document.querySelector("#email-input")
const messageInput = document.querySelector("#message-input")
const formInfo = document.querySelector(".form-info")
messageInput.addEventListener("input", () => {
messageInput.classList.remove("error")
formInfo.classList.remove("success")
formInfo.innerText = ""
})
function sendMail() {
if (timeout) {
formInfo.classList.remove("success")
formInfo.innerText = "You must wait 1 minute before your next request."
return
}
let tempParams = {
name: nameInput.value,
email: emailInput.value,
message: messageInput.value
}
emailjs.send("service_0mdrl8s", "template_2f97bv3", tempParams).then(res => console.log("Success " + res.status))
formInfo.classList.add("success")
formInfo.innerText = "Message sent succesfully!"
timeout = true
setTimeout(() => {
timeout = false
}, 60000);
}
function validateInputs(event) {
event.preventDefault();
if (!messageInput.value.trim()) {
messageInput.classList.add("error")
formInfo.classList.remove("success")
formInfo.innerText = "Fill in the required fields."
} else {
messageInput.classList.remove("error")
sendMail()
}
}
document.querySelector("form").addEventListener("submit", validateInputs)
// #endregion
// #region | Vanilla Tilt Cards
VanillaTilt.init(document.querySelectorAll(".card"), {
glare: true,
// reverse: true,
"max-glare": 0.1,
speed: 1000,
})
// #endregion
// #region | cards carousel slider
let splide = new Splide('.splide', {
// type: 'loop',
drag: 'free',
perPage: 3,
perMove: 1,
rewind: true,
focus: 'center',
pagination: true,
width: `${3 * 320 + 110}px`,
gap: "20px",
waitForTransition: false,
padding: "18px",
breakpoints: {
1230: {
perPage: 2,
focus: 1,
width: `${2 * 320 + 110}px`,
},
970: {
perPage: 1,
width: `${440}px`,
}
}
});
splide.mount();
// #endregion