-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
187 lines (172 loc) · 4.84 KB
/
app.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
const containers = document.querySelectorAll(".input-container");
const form = document.querySelector("form");
const tl = gsap.timeline({ defaults: { duration: 1 } });
//Line
const start =
"M0 0.999512C0 0.999512 60.5 0.999512 150 0.999512C239.5 0.999512 300 0.999512 300 0.999512";
const end =
"M1 0.999512C1 0.999512 61.5 7.5 151 7.5C240.5 7.5 301 0.999512 301 0.999512";
//Elastic Effect
containers.forEach((container) => {
const input = container.querySelector(".input");
const line = container.querySelector(".elastic-line");
const placeholder = container.querySelector(".placeholder");
input.addEventListener("focus", () => {
//Check to see if there is any text in the input
if (!input.value) {
tl.fromTo(
line,
{ attr: { d: start } },
{ attr: { d: end }, ease: "Power2.easeOut", duration: 0.75 }
);
tl.to(line, { attr: { d: start }, ease: "elastic.out(3,0.5)" }, "<50%");
//Placeholder Shift
tl.to(
placeholder,
{
top: -15,
left: 0,
scale: 0.7,
duration: 0.5,
ease: "Power2.easeOut",
},
"<15%"
);
}
});
});
//Revert back if it's not focused
form.addEventListener("click", () => {
containers.forEach((container) => {
const input = container.querySelector(".input");
const line = container.querySelector(".elastic-line");
const placeholder = container.querySelector(".placeholder");
if (document.activeElement !== input) {
if (!input.value) {
gsap.to(placeholder, {
top: 0,
left: 0,
scale: 1,
duration: 0.5,
ease: "Power2.easeOut",
});
}
}
//We will do our validation
//Name Validation
input.addEventListener("input", (e) => {
if (e.target.type === "text") {
let inputText = e.target.value;
if (inputText.length > 2) {
colorize("#6391E8", line, placeholder);
} else {
colorize("#FE8C99", line, placeholder);
}
}
//Validate Email
if (e.target.type === "email") {
let valid = validateEmail(e.target.value);
if (valid) {
colorize("#6391E8", line, placeholder);
} else {
colorize("#FE8C99", line, placeholder);
}
}
//Validate Phone
if (e.target.type === "tel") {
let valid = validatePhone(e.target.value);
if (valid) {
colorize("#6391E8", line, placeholder);
} else {
colorize("#FE8C99", line, placeholder);
}
}
});
});
});
// checking email validation
function validateEmail(email) {
let re = /\S+@\S+\.\S+/;
return re.test(email);
}
function validatePhone(phone) {
let re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;
return re.test(phone);
}
//COLORIZE FUNCTION
function colorize(color, line, placeholder) {
gsap.to(line, { stroke: color, duration: 0.75 });
gsap.to(placeholder, { color: color, duration: 0.75 });
}
//Checkbox animation fill
const checkbox = document.querySelector(".checkbox");
const tl2 = gsap.timeline({
defaults: { duration: 0.5, ease: "Power2.easeOut" },
});
const tickMarkPath = document.querySelector(".tick-mark path");
const pathLength = tickMarkPath.getTotalLength();
gsap.set(tickMarkPath, {
strokeDashoffset: pathLength,
strokeDasharray: pathLength,
});
checkbox.addEventListener("click", () => {
if (checkbox.checked) {
tl2.to(".checkbox-fill", { top: "0%" });
tl2.fromTo(
tickMarkPath,
{ strokeDashoffset: pathLength },
{ strokeDashoffset: 0 },
"<50%"
);
tl2.to(".checkbox-label", { color: "#6391e8" }, "<");
} else {
tl2.to(".checkbox-fill", { top: "100%" });
tl2.fromTo(
tickMarkPath,
{ strokeDashoffset: 0 },
{ strokeDashoffset: pathLength },
"<50%"
);
tl2.to(".checkbox-label", { color: "#c5c5c5" }, "<");
}
});
//Animating Character
gsap.set("#eye", { transformOrigin: "center" });
gsap.fromTo(
"#eye",
{ scaleY: 1 },
{
scaleY: 0.3,
repeat: -1,
yoyo: true,
repeatDelay: 0.5,
ease: "Power2.easeOut",
}
);
gsap.fromTo(
"#eyebrow",
{ y: 0 },
{ y: -1, repeat: -1, yoyo: true, repeatDelay: 0.5, ease: "Power2.easeOut" }
);
//Submit button
const button = document.querySelector("button");
const tl3 = gsap.timeline({
defaults: { duration: 0.75, ease: "Power2.easeOut" },
});
button.addEventListener("click", (e) => {
e.preventDefault();
tl3.to(".contact-right, .contact-left", {
y: 30,
opacity: 0,
pointerEvents: "none",
});
tl3.to("form", { scale: 0.8 }, "<");
tl3.fromTo(".submitted", { opacity: 0, y: 30 }, { opacity: 1, y: 0 });
//Hand wave
gsap.set("#hand", { transformOrigin: "left" });
gsap.fromTo(
"#hand",
{ rotation: 0, y: 0 },
{ rotation: -10, y: 2, ease: "elastic(3,0.3)", duration: 2, delay: 1 }
);
});