-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
128 lines (107 loc) · 3.52 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
const title = document.querySelector('h1');
const yesBtn = document.getElementById('yesBtn');
const noBtn = document.getElementById('noBtn');
const responseText = document.getElementById('responseText');
const gif = document.querySelector('.gif');
const hoverSound = document.getElementById('hoverSound');
const yesSound = document.getElementById('yesSound');
const noSound = document.getElementById('noSound');
yesBtn.addEventListener('click', () => {
responseText.textContent = 'Ура! Я так рада! 💖 💞';
gif.src = 'https://i.pinimg.com/originals/b4/65/34/b46534530b0ef3ffac6636f068dd2e12.gif';
yesBtn.style.display = 'none';
noBtn.style.display = 'none';
title.style.color = 'transparent';
title.style.height = '0';
title.style.margin = '0';
});
yesBtn.addEventListener('click', () => {
confetti({
particleCount: 100,
spread: 70,
origin: { y: 0.6 }
});
});
noBtn.addEventListener('mouseover', () => {
const x = Math.random() * (window.innerWidth - noBtn.offsetWidth);
const y = Math.random() * (window.innerHeight - noBtn.offsetHeight);
noBtn.style.position = 'absolute';
noBtn.style.left = `${x}px`;
noBtn.style.top = `${y}px`;
});
noBtn.addEventListener('click', () => {
responseText.textContent = 'Нет? Ну ладно, но ты всё равно моя валентинка! 🤭';
gif.src = 'https://i.pinimg.com/originals/3e/47/7e/3e477e83c35e2a7a38f19ccdad163faa.gif';
yesBtn.style.display = 'none';
noBtn.style.display = 'none';
title.style.display = 'none';
});
// hearts animation
const canvas = document.getElementById('heartsCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
document.addEventListener('mousemove', (e) => {
const heart = new Heart();
heart.x = e.clientX;
heart.y = e.clientY;
heart.size = 10;
heart.speed = 1;
hearts.push(heart);
});
const hearts = [];
class Heart {
constructor() {
this.x = Math.random() * canvas.width;
this.y = -50;
this.size = Math.random() * 20 + 10;
this.speed = Math.random() * 2 + 1;
this.color = Math.random() > 0.5 ? '#ff6f61' : '#ff3b2f';
}
draw() {
ctx.beginPath();
ctx.moveTo(this.x, this.y);
ctx.bezierCurveTo(this.x - this.size / 2, this.y - this.size / 4, this.x - this.size, this.y + this.size / 2, this.x, this.y + this.size);
ctx.bezierCurveTo(this.x + this.size, this.y + this.size / 2, this.x + this.size / 2, this.y - this.size / 4, this.x, this.y);
ctx.closePath();
ctx.fillStyle = this.color;
ctx.fill();
}
update() {
this.y += this.speed;
if (this.y > canvas.height) {
this.y = -50;
this.x = Math.random() * canvas.width;
}
this.draw();
}
}
function init() {
for (let i = 0; i < 50; i++) {
hearts.push(new Heart());
}
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
hearts.forEach(heart => heart.update());
requestAnimationFrame(animate);
}
init();
animate();
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
// sounds
yesBtn.addEventListener('mouseenter', () => {
hoverSound.play();
});
noBtn.addEventListener('mouseenter', () => {
hoverSound.play();
});
yesBtn.addEventListener('click', () => {
yesSound.play();
});
noBtn.addEventListener('click', () => {
noSound.play();
});