-
Notifications
You must be signed in to change notification settings - Fork 1
/
scripts.js
158 lines (133 loc) · 4.84 KB
/
scripts.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
function checkPassword() {
const password = document.getElementById('password').value;
const errorMessage = document.getElementById('error-message');
const correctPassword = 'yeuembethuky';
if (password === correctPassword) {
document.getElementById('login').style.display = 'none';
document.getElementById('main-content').style.display = 'block';
initiateAnimations();
} else {
errorMessage.textContent = 'Incorrect password. Please try again.';
}
}
function initiateAnimations() {
const observerOptions = {
threshold: 0.5
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
const elements = document.querySelectorAll('.fade-in, .slide-up');
elements.forEach(el => observer.observe(el));
}
document.addEventListener('DOMContentLoaded', () => {
initiateAnimations();
const passwordInput = document.getElementById('password');
passwordInput.addEventListener('keypress', (event) => {
if (event.key === 'Enter') {
checkPassword();
}
});
});
function initiateAnimations1() {
const observerOptions = {
threshold: 0.1,
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
const elements = document.querySelectorAll('.timeline-item, .slide-up');
elements.forEach(el => observer.observe(el));
}
function triggerConfetti() {
confetti({
particleCount: 150,
spread: 70,
origin: { y: 0.6 }
});
}
let confettiTriggered = false;
window.addEventListener('scroll', () => {
if (!confettiTriggered) {
triggerConfetti();
confettiTriggered = true;
}
});
document.addEventListener('DOMContentLoaded', () => {
initiateAnimations1();
});
function submitQuiz() {
const correctAnswers = {
q1: 'Black',
q2: 'Despicable Me 4',
q3: 'Bun Bo Hue',
q4: 'Tokyo',
q5: '9Gaming'
};
const userAnswers = {
q1: document.querySelector('input[name="q1"]:checked') ? document.querySelector('input[name="q1"]:checked').value : '',
q2: document.querySelector('input[name="q2"]:checked') ? document.querySelector('input[name="q2"]:checked').value : '',
q3: document.querySelector('input[name="q3"]:checked') ? document.querySelector('input[name="q3"]:checked').value : '',
q4: document.querySelector('input[name="q4"]:checked') ? document.querySelector('input[name="q4"]:checked').value : '',
q5: document.querySelector('input[name="q5"]:checked') ? document.querySelector('input[name="q5"]:checked').value : ''
};
let score = 0;
for (const question in correctAnswers) {
if (userAnswers[question] === correctAnswers[question]) {
score++;
}
}
const resultElement = document.getElementById( 'quiz-result' );
if ( score === 5 ) {
resultElement.textContent = `Babe, You got ${ score } out of 5 questions correct! 🎉 Turns out you understand me more than I'd think hehee`
} else if ( score >= 3 ) {
resultElement.textContent = `Babe, You got ${ score } out of 5 questions correct! 🎉 Not bad, you know me quite well ^^`
} else {
resultElement.textContent = `Babe, You got ${ score } out of 5 questions correct! 😅 It's okay, I still love you ==`
}
}
function updateCountdown(targetDate, countdownId) {
const now = new Date().getTime();
const distance = targetDate - now;
if (distance >= 0) {
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById(`days-${countdownId}`).textContent = days;
document.getElementById(`hours-${countdownId}`).textContent = hours;
document.getElementById(`minutes-${countdownId}`).textContent = minutes;
document.getElementById(`seconds-${countdownId}`).textContent = seconds;
} else {
document.getElementById(`countdown-${countdownId}`).textContent = "The time has come!";
}
}
const vietnamDate = new Date('December 15, 2024 00:00:00').getTime();
const birthdayDate = new Date('November 9, 2024 00:00:00').getTime();
setInterval(() => {
updateCountdown(vietnamDate, 'vn');
updateCountdown(birthdayDate, 'bd');
}, 1000);
document.getElementById('scroll-to-top').addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
document.getElementById('trigger-confetti').addEventListener('click', function() {
confetti({
particleCount: 150,
spread: 70,
origin: { y: 0.6 }
});
});