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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// trigger to play music in the background with sweetalert
|
| 2 |
+
window.addEventListener('load', () => {
|
| 3 |
+
Swal.fire({
|
| 4 |
+
title: 'Do you want to play music in the background?',
|
| 5 |
+
icon: 'warning',
|
| 6 |
+
showCancelButton: true,
|
| 7 |
+
confirmButtonColor: '#3085d6',
|
| 8 |
+
cancelButtonColor: '#d33',
|
| 9 |
+
confirmButtonText: 'Yes',
|
| 10 |
+
cancelButtonText: 'No',
|
| 11 |
+
}).then((result) => {
|
| 12 |
+
if (result.isConfirmed) {
|
| 13 |
+
document.querySelector('.song').play();
|
| 14 |
+
animationTimeline();
|
| 15 |
+
} else {
|
| 16 |
+
animationTimeline();
|
| 17 |
+
}
|
| 18 |
+
});
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
// animation timeline
|
| 23 |
+
const animationTimeline = () => {
|
| 24 |
+
// split chars that needs to be animated individually
|
| 25 |
+
const textBoxChars = document.getElementsByClassName("hbd-chatbox")[0];
|
| 26 |
+
const hbd = document.getElementsByClassName("wish-hbd")[0];
|
| 27 |
+
|
| 28 |
+
textBoxChars.innerHTML = `<span>${textBoxChars.innerHTML
|
| 29 |
+
.split("")
|
| 30 |
+
.join("</span><span>")}</span>`;
|
| 31 |
+
|
| 32 |
+
hbd.innerHTML = `<span>${hbd.innerHTML
|
| 33 |
+
.split("")
|
| 34 |
+
.join("</span><span>")}</span>`;
|
| 35 |
+
|
| 36 |
+
const ideaTextTrans = {
|
| 37 |
+
opacity: 0,
|
| 38 |
+
y: -20,
|
| 39 |
+
rotationX: 5,
|
| 40 |
+
skewX: "15deg"
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
const ideaTextTransLeave = {
|
| 44 |
+
opacity: 0,
|
| 45 |
+
y: 20,
|
| 46 |
+
rotationY: 5,
|
| 47 |
+
skewX: "-15deg"
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// timeline
|
| 51 |
+
const tl = new TimelineMax();
|
| 52 |
+
|
| 53 |
+
tl.to(".container", 0.6, {
|
| 54 |
+
visibility: "visible"
|
| 55 |
+
})
|
| 56 |
+
.from(".one", 0.7, {
|
| 57 |
+
opacity: 0,
|
| 58 |
+
y: 10
|
| 59 |
+
})
|
| 60 |
+
.from(".two", 0.4, {
|
| 61 |
+
opacity: 0,
|
| 62 |
+
y: 10
|
| 63 |
+
})
|
| 64 |
+
.to(".one",
|
| 65 |
+
0.7,
|
| 66 |
+
{
|
| 67 |
+
opacity: 0,
|
| 68 |
+
y: 10
|
| 69 |
+
},
|
| 70 |
+
"+=3.5")
|
| 71 |
+
.to(".two",
|
| 72 |
+
0.7,
|
| 73 |
+
{
|
| 74 |
+
opacity: 0,
|
| 75 |
+
y: 10
|
| 76 |
+
},
|
| 77 |
+
"-=1")
|
| 78 |
+
.from(".three", 0.7, {
|
| 79 |
+
opacity: 0,
|
| 80 |
+
y: 10
|
| 81 |
+
})
|
| 82 |
+
.to(".three",
|
| 83 |
+
0.7,
|
| 84 |
+
{
|
| 85 |
+
opacity: 0,
|
| 86 |
+
y: 10
|
| 87 |
+
},
|
| 88 |
+
"+=3")
|
| 89 |
+
.from(".four", 0.7, {
|
| 90 |
+
scale: 0.2,
|
| 91 |
+
opacity: 0,
|
| 92 |
+
})
|
| 93 |
+
.from(".fake-btn", 0.3, {
|
| 94 |
+
scale: 0.2,
|
| 95 |
+
opacity: 0,
|
| 96 |
+
})
|
| 97 |
+
.staggerTo(
|
| 98 |
+
".hbd-chatbox span",
|
| 99 |
+
1.5, {
|
| 100 |
+
visibility: "visible",
|
| 101 |
+
},
|
| 102 |
+
0.05
|
| 103 |
+
)
|
| 104 |
+
.to(".fake-btn", 0.1, {
|
| 105 |
+
backgroundColor: "rgb(127, 206, 248)",
|
| 106 |
+
},
|
| 107 |
+
"+=4")
|
| 108 |
+
.to(
|
| 109 |
+
".four",
|
| 110 |
+
0.5, {
|
| 111 |
+
scale: 0.2,
|
| 112 |
+
opacity: 0,
|
| 113 |
+
y: -150
|
| 114 |
+
},
|
| 115 |
+
"+=1")
|
| 116 |
+
.from(".idea-1", 0.7, ideaTextTrans)
|
| 117 |
+
.to(".idea-1", 0.7, ideaTextTransLeave, "+=2.5")
|
| 118 |
+
.from(".idea-2", 0.7, ideaTextTrans)
|
| 119 |
+
.to(".idea-2", 0.7, ideaTextTransLeave, "+=2.5")
|
| 120 |
+
.from(".idea-3", 0.7, ideaTextTrans)
|
| 121 |
+
.to(".idea-3 strong", 0.5, {
|
| 122 |
+
scale: 1.2,
|
| 123 |
+
x: 10,
|
| 124 |
+
backgroundColor: "rgb(21, 161, 237)",
|
| 125 |
+
color: "#fff",
|
| 126 |
+
})
|
| 127 |
+
.to(".idea-3", 0.7, ideaTextTransLeave, "+=2.5")
|
| 128 |
+
.from(".idea-4", 0.7, ideaTextTrans)
|
| 129 |
+
.to(".idea-4", 0.7, ideaTextTransLeave, "+=2.5")
|
| 130 |
+
.from(
|
| 131 |
+
".idea-5",
|
| 132 |
+
0.7, {
|
| 133 |
+
rotationX: 15,
|
| 134 |
+
rotationZ: -10,
|
| 135 |
+
skewY: "-5deg",
|
| 136 |
+
y: 50,
|
| 137 |
+
z: 10,
|
| 138 |
+
opacity: 0,
|
| 139 |
+
},
|
| 140 |
+
"+=1.5"
|
| 141 |
+
)
|
| 142 |
+
.to(
|
| 143 |
+
".idea-5 span",
|
| 144 |
+
0.7, {
|
| 145 |
+
rotation: 90,
|
| 146 |
+
x: 8,
|
| 147 |
+
},
|
| 148 |
+
"+=1.4"
|
| 149 |
+
)
|
| 150 |
+
.to(
|
| 151 |
+
".idea-5",
|
| 152 |
+
0.7, {
|
| 153 |
+
scale: 0.2,
|
| 154 |
+
opacity: 0,
|
| 155 |
+
},
|
| 156 |
+
"+=2"
|
| 157 |
+
)
|
| 158 |
+
.staggerFrom(
|
| 159 |
+
".idea-6 span",
|
| 160 |
+
0.8, {
|
| 161 |
+
scale: 3,
|
| 162 |
+
opacity: 0,
|
| 163 |
+
rotation: 15,
|
| 164 |
+
ease: Expo.easeOut,
|
| 165 |
+
},
|
| 166 |
+
0.2
|
| 167 |
+
)
|
| 168 |
+
.staggerTo(
|
| 169 |
+
".idea-6 span",
|
| 170 |
+
0.8, {
|
| 171 |
+
scale: 3,
|
| 172 |
+
opacity: 0,
|
| 173 |
+
rotation: -15,
|
| 174 |
+
ease: Expo.easeOut,
|
| 175 |
+
},
|
| 176 |
+
0.2,
|
| 177 |
+
"+=1.5"
|
| 178 |
+
)
|
| 179 |
+
.staggerFromTo(
|
| 180 |
+
".baloons img",
|
| 181 |
+
2.5, {
|
| 182 |
+
opacity: 0.9,
|
| 183 |
+
y: 1400,
|
| 184 |
+
}, {
|
| 185 |
+
opacity: 1,
|
| 186 |
+
y: -1000,
|
| 187 |
+
},
|
| 188 |
+
0.2
|
| 189 |
+
)
|
| 190 |
+
.from(
|
| 191 |
+
".profile-picture",
|
| 192 |
+
0.5, {
|
| 193 |
+
scale: 3.5,
|
| 194 |
+
opacity: 0,
|
| 195 |
+
x: 25,
|
| 196 |
+
y: -25,
|
| 197 |
+
rotationZ: -45,
|
| 198 |
+
},
|
| 199 |
+
"-=2"
|
| 200 |
+
)
|
| 201 |
+
.from(".hat", 0.5, {
|
| 202 |
+
x: -100,
|
| 203 |
+
y: 350,
|
| 204 |
+
rotation: -180,
|
| 205 |
+
opacity: 0,
|
| 206 |
+
})
|
| 207 |
+
.staggerFrom(
|
| 208 |
+
".wish-hbd span",
|
| 209 |
+
0.7, {
|
| 210 |
+
opacity: 0,
|
| 211 |
+
y: -50,
|
| 212 |
+
// scale: 0.3,
|
| 213 |
+
rotation: 150,
|
| 214 |
+
skewX: "30deg",
|
| 215 |
+
ease: Elastic.easeOut.config(1, 0.5),
|
| 216 |
+
},
|
| 217 |
+
0.1
|
| 218 |
+
)
|
| 219 |
+
.staggerFromTo(
|
| 220 |
+
".wish-hbd span",
|
| 221 |
+
0.7, {
|
| 222 |
+
scale: 1.4,
|
| 223 |
+
rotationY: 150,
|
| 224 |
+
}, {
|
| 225 |
+
scale: 1,
|
| 226 |
+
rotationY: 0,
|
| 227 |
+
color: "#ff69b4",
|
| 228 |
+
ease: Expo.easeOut,
|
| 229 |
+
},
|
| 230 |
+
0.1,
|
| 231 |
+
"party"
|
| 232 |
+
)
|
| 233 |
+
.from(
|
| 234 |
+
".wish h5",
|
| 235 |
+
0.5, {
|
| 236 |
+
opacity: 0,
|
| 237 |
+
y: 10,
|
| 238 |
+
skewX: "-15deg",
|
| 239 |
+
},
|
| 240 |
+
"party"
|
| 241 |
+
)
|
| 242 |
+
.staggerTo(
|
| 243 |
+
".eight svg",
|
| 244 |
+
1.5, {
|
| 245 |
+
visibility: "visible",
|
| 246 |
+
opacity: 0,
|
| 247 |
+
scale: 80,
|
| 248 |
+
repeat: 3,
|
| 249 |
+
repeatDelay: 1.4,
|
| 250 |
+
},
|
| 251 |
+
0.3
|
| 252 |
+
)
|
| 253 |
+
.to(".six", 0.5, {
|
| 254 |
+
opacity: 0,
|
| 255 |
+
y: 30,
|
| 256 |
+
zIndex: "-1",
|
| 257 |
+
})
|
| 258 |
+
.staggerFrom(".nine p", 1, ideaTextTrans, 1.2)
|
| 259 |
+
.to(
|
| 260 |
+
".last-smile",
|
| 261 |
+
0.5, {
|
| 262 |
+
rotation: 90,
|
| 263 |
+
},
|
| 264 |
+
"+=1"
|
| 265 |
+
);
|
| 266 |
+
|
| 267 |
+
// Restart Animation on click
|
| 268 |
+
const replyBtn = document.getElementById("replay");
|
| 269 |
+
replyBtn.addEventListener("click", () => {
|
| 270 |
+
tl.restart();
|
| 271 |
+
});
|
| 272 |
+
}
|