-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
63 lines (54 loc) · 1.36 KB
/
main.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
import Typed from "typed.js";
import confetti from "canvas-confetti";
const typed = new Typed("#intro", {
strings: ["Welcome.", "Thank you for visiting.", "Have a wonderful day."],
typeSpeed: 50,
loop: true,
});
const appreciateBtn = document.getElementById("appreciate");
const myCanvas = document.createElement("canvas");
const myConfetti = confetti.create(myCanvas, {
resize: true,
useWorker: true,
});
appreciateBtn.addEventListener("click", () => {
myCanvas.style.position = "fixed";
myCanvas.style.inset = 0;
myCanvas.style.width = "100vw";
myCanvas.style.height = "100vh";
myCanvas.style.zIndex = 1;
document.body.appendChild(myCanvas);
myConfetti({
particleCount: 100,
startVelocity: 30,
spread: 360,
origin: {
x: Math.random(),
// since they fall down, start a bit higher than random
y: Math.random() - 0.2
}
});
});
// do this for 1 seconds
var duration = 1 * 1000;
var end = Date.now() + duration;
(function frame() {
// launch a few confetti from the left edge
confetti({
particleCount: 7,
angle: 60,
spread: 55,
origin: { x: 0 }
});
// and launch a few from the right edge
confetti({
particleCount: 7,
angle: 120,
spread: 55,
origin: { x: 1 }
});
// keep going until we are out of time
if (Date.now() < end) {
requestAnimationFrame(frame);
}
}());