JSFiddle - React, Tailwind, and code Playground

by ckissi

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>iPhone Island Notification</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="notification-container">
        <div class="notification-content">
            <p>New Notification</p>
        </div>
    </div>

 
</body>
</html>

CSS

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f0f0f0;
    margin: 0;
}

.notification-container {
    position: absolute;
    top: 20px;
    width: 200px;
    height: 50px;
    background-color: black;
    color: white;
    border-radius: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.3s ease-in-out;
}

.notification-container.show {
    opacity: 1;
    transform: scale(1);
}

.notification-content {
    display: flex;
    justify-content: center;
    align-items: center;
}

JavaScript

document.addEventListener('DOMContentLoaded', function() {
    const notificationContainer = document.querySelector('.notification-container');

    function showNotification() {
        notificationContainer.classList.add('show');
        setTimeout(hideNotification, 3000); // Hide after 3 seconds
    }

    function hideNotification() {
        notificationContainer.classList.remove('show');
    }

    // Simulate a notification after 1 second
    setTimeout(showNotification, 1000);
});