Skip to content

Commit 6bdee4c

Browse files
committed
chore: add animation
1 parent 90c12eb commit 6bdee4c

1 file changed

Lines changed: 105 additions & 3 deletions

File tree

src/components/Hero.astro

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ const notifications = [
100100
</div>
101101
</div>
102102

103-
<div id="phone-notifications" class="px-2">
104-
{notifications.map((noti) => (
105-
<div class="flex flex-row p-4 text-white font-normal">
103+
<div id="phone-notifications" class="px-2 relative">
104+
{notifications.map((noti, index) => (
105+
<div class="notification flex flex-row p-4 text-white font-normal absolute w-full" style={index > 0 ? "display: none;" : ""}>
106106
<img src={`/images/logos/${noti.channel.toLowerCase()}.svg`} class="w-8 h-8" />
107107
<div class="flex flex-col ml-4">
108108
<div class="font-bold">{noti.channel}<span class="ml-2 opacity-75 text-xs font-normal">now</span></div>
@@ -146,4 +146,106 @@ const notifications = [
146146
transform: rotate(-360deg);
147147
}
148148
}
149+
150+
/* Notification animation styles */
151+
#phone-notifications {
152+
min-height: 140px;
153+
overflow: hidden;
154+
}
155+
156+
.notification {
157+
transition: opacity 0.5s ease, transform 0.5s ease;
158+
opacity: 0;
159+
transform: translateY(100%); /* Start from bottom */
160+
left: 0;
161+
right: 0;
162+
}
163+
164+
.notification.active {
165+
opacity: 1;
166+
transform: translateY(0); /* Centered position */
167+
}
168+
169+
.notification.slide-out {
170+
opacity: 0;
171+
transform: translateY(-20%) scale(0.9);
172+
}
149173
</style>
174+
175+
<script>
176+
// Function to animate notifications
177+
function animateNotifications() {
178+
const notifications = document.querySelectorAll<HTMLDivElement>('#phone-notifications .notification');
179+
if (notifications.length === 0) return;
180+
181+
let currentIndex = 0;
182+
183+
// Show the first notification initially
184+
notifications[0].classList.add('active');
185+
186+
// Function to rotate to the next notification
187+
function rotateNotifications() {
188+
// Calculate next index
189+
const nextIndex = (currentIndex + 1) % notifications.length;
190+
191+
// Add slide-out class to current notification
192+
notifications[currentIndex].classList.remove('active');
193+
notifications[currentIndex].classList.add('slide-out');
194+
195+
// Show next notification immediately
196+
notifications[nextIndex].style.display = 'flex';
197+
198+
// Small delay before adding active class for animation
199+
setTimeout(() => {
200+
notifications[nextIndex].classList.add('active');
201+
}, 50);
202+
203+
// After animation completes, hide the old notification and update current index
204+
setTimeout(() => {
205+
notifications[currentIndex].classList.remove('slide-out');
206+
notifications[currentIndex].style.display = 'none';
207+
currentIndex = nextIndex;
208+
}, 500);
209+
}
210+
211+
// Rotate notifications every 5 seconds
212+
setInterval(rotateNotifications, 5_000);
213+
}
214+
215+
// Function to update phone time and date
216+
function updatePhoneTimeAndDate() {
217+
const timeElement = document.getElementById('phone-time');
218+
const dateElement = document.getElementById('phone-date');
219+
220+
if (!timeElement || !dateElement) return;
221+
222+
function update() {
223+
const now = new Date();
224+
225+
// Update time (HH:MM format)
226+
const hours = now.getHours().toString().padStart(2, '0');
227+
const minutes = now.getMinutes().toString().padStart(2, '0');
228+
timeElement!.textContent = `${hours}:${minutes}`;
229+
230+
// Update date (Day of week, Month Day format)
231+
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
232+
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
233+
234+
const dayOfWeek = days[now.getDay()];
235+
const month = months[now.getMonth()];
236+
const dayOfMonth = now.getDate();
237+
238+
dateElement!.textContent = `${dayOfWeek}, ${month} ${dayOfMonth}`;
239+
}
240+
241+
// Update immediately and then every minute
242+
update();
243+
setInterval(update, 60000);
244+
}
245+
246+
// Initialize when the DOM is loaded
247+
document.addEventListener('DOMContentLoaded', () => {
248+
animateNotifications();
249+
updatePhoneTimeAndDate();
250+
});
251+
</script>

0 commit comments

Comments
 (0)