-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (91 loc) · 3.2 KB
/
script.js
File metadata and controls
108 lines (91 loc) · 3.2 KB
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
// Create floating hearts in background
function createBackgroundHearts() {
const container = document.getElementById('heartsContainer');
const heartEmojis = ['❤️', '💕', '💖', '💗', '💝', '💓', '💞'];
setInterval(() => {
const heart = document.createElement('div');
heart.className = 'bg-heart';
heart.textContent = heartEmojis[Math.floor(Math.random() * heartEmojis.length)];
heart.style.left = Math.random() * 100 + '%';
heart.style.animationDuration = (Math.random() * 4 + 6) + 's';
heart.style.fontSize = (Math.random() * 20 + 15) + 'px';
container.appendChild(heart);
setTimeout(() => {
heart.remove();
}, 10000);
}, 800);
}
// Envelope click handler
const envelopeWrapper = document.getElementById('envelopeWrapper');
const letterContainer = document.getElementById('letterContainer');
const closeBtn = document.getElementById('closeBtn');
envelopeWrapper.addEventListener('click', () => {
envelopeWrapper.classList.add('hidden');
setTimeout(() => {
envelopeWrapper.style.display = 'none';
letterContainer.classList.add('active');
}, 800);
});
// Close button handler
closeBtn.addEventListener('click', () => {
letterContainer.classList.remove('active');
setTimeout(() => {
envelopeWrapper.style.display = 'flex';
envelopeWrapper.classList.remove('hidden');
}, 500);
});
// Add sparkle effect on mouse move
document.addEventListener('mousemove', (e) => {
if (Math.random() > 0.95) {
const sparkle = document.createElement('div');
sparkle.textContent = '✨';
sparkle.style.position = 'fixed';
sparkle.style.left = e.clientX + 'px';
sparkle.style.top = e.clientY + 'px';
sparkle.style.pointerEvents = 'none';
sparkle.style.fontSize = '20px';
sparkle.style.animation = 'sparkleDisappear 1s ease forwards';
sparkle.style.zIndex = '1000';
document.body.appendChild(sparkle);
setTimeout(() => sparkle.remove(), 1000);
}
});
// Add sparkle animation
const style = document.createElement('style');
style.textContent = `
@keyframes sparkleDisappear {
0% {
opacity: 1;
transform: scale(0) rotate(0deg);
}
50% {
opacity: 1;
transform: scale(1.5) rotate(180deg);
}
100% {
opacity: 0;
transform: scale(0) rotate(360deg);
}
}
`;
document.head.appendChild(style);
// Initialize
createBackgroundHearts();
// Add typing effect to letter content
function typeWriter(element, text, speed = 50) {
let i = 0;
element.textContent = '';
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Optional: Add click sound effect
envelopeWrapper.addEventListener('click', () => {
// You can add a sound effect here if desired
console.log('💌 Opening love letter...');
});