| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Age Calculator</title> |
| <script src="https://cdn.tailwindcss.com"></script> |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> |
| <style> |
| @keyframes fadeIn { |
| from { opacity: 0; transform: translateY(20px); } |
| to { opacity: 1; transform: translateY(0); } |
| } |
| .animate-fade-in { |
| animation: fadeIn 0.8s ease-out forwards; |
| } |
| .glow { |
| box-shadow: 0 0 15px rgba(99, 102, 241, 0.5); |
| } |
| .result-box { |
| transition: all 0.5s ease; |
| } |
| .hidden { |
| opacity: 0; |
| height: 0; |
| overflow: hidden; |
| } |
| .visible { |
| opacity: 1; |
| height: auto; |
| } |
| </style> |
| </head> |
| <body class="bg-gradient-to-br from-indigo-100 to-purple-100 min-h-screen flex items-center justify-center p-4"> |
| <div class="max-w-md w-full bg-white rounded-xl shadow-2xl overflow-hidden animate-fade-in"> |
| <div class="bg-gradient-to-r from-indigo-500 to-purple-600 p-6 text-white"> |
| <div class="flex items-center justify-between"> |
| <h1 class="text-2xl font-bold">Age Calculator</h1> |
| <i class="fas fa-calculator text-3xl"></i> |
| </div> |
| <p class="mt-2 opacity-90">Discover your exact age in years</p> |
| </div> |
| |
| <div class="p-6"> |
| <div class="mb-6"> |
| <label for="birthYear" class="block text-gray-700 font-medium mb-2">Enter your birth year:</label> |
| <div class="relative"> |
| <input type="number" id="birthYear" |
| class="w-full px-4 py-3 rounded-lg border-2 border-gray-300 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 outline-none transition" |
| placeholder="e.g. 1990" min="1900" max="2099"> |
| <i class="fas fa-calendar-alt absolute right-3 top-3.5 text-gray-400"></i> |
| </div> |
| <p id="errorMessage" class="text-red-500 text-sm mt-1 hidden">Please enter a valid year between 1900 and current year.</p> |
| </div> |
| |
| <button id="calculateBtn" |
| class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-lg transition duration-300 transform hover:scale-105 glow"> |
| Calculate Age |
| </button> |
| |
| <div id="resultContainer" class="result-box mt-6 hidden"> |
| <div class="bg-indigo-50 rounded-lg p-4 border-l-4 border-indigo-500"> |
| <div class="flex items-center"> |
| <i class="fas fa-user-clock text-indigo-600 text-2xl mr-3"></i> |
| <div> |
| <h3 class="font-semibold text-gray-800">Your Age</h3> |
| <p id="ageResult" class="text-3xl font-bold text-indigo-700 mt-1">0 years</p> |
| </div> |
| </div> |
| <div class="mt-4 flex justify-between text-sm text-gray-600"> |
| <span id="birthYearDisplay"></span> |
| <span id="currentYearDisplay"></span> |
| </div> |
| </div> |
| |
| <div class="mt-4 grid grid-cols-3 gap-2"> |
| <div class="bg-purple-50 p-3 rounded-lg text-center"> |
| <p class="text-xs text-purple-600">Months</p> |
| <p id="months" class="font-bold text-purple-800">0</p> |
| </div> |
| <div class="bg-blue-50 p-3 rounded-lg text-center"> |
| <p class="text-xs text-blue-600">Days</p> |
| <p id="days" class="font-bold text-blue-800">0</p> |
| </div> |
| <div class="bg-green-50 p-3 rounded-lg text-center"> |
| <p class="text-xs text-green-600">Hours</p> |
| <p id="hours" class="font-bold text-green-800">0</p> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <div class="bg-gray-50 px-6 py-4 text-center text-sm text-gray-500"> |
| <p>© 2023 Age Calculator | Made with <i class="fas fa-heart text-red-400"></i></p> |
| </div> |
| </div> |
|
|
| <script> |
| document.addEventListener('DOMContentLoaded', function() { |
| const birthYearInput = document.getElementById('birthYear'); |
| const calculateBtn = document.getElementById('calculateBtn'); |
| const resultContainer = document.getElementById('resultContainer'); |
| const ageResult = document.getElementById('ageResult'); |
| const birthYearDisplay = document.getElementById('birthYearDisplay'); |
| const currentYearDisplay = document.getElementById('currentYearDisplay'); |
| const errorMessage = document.getElementById('errorMessage'); |
| const monthsDisplay = document.getElementById('months'); |
| const daysDisplay = document.getElementById('days'); |
| const hoursDisplay = document.getElementById('hours'); |
| |
| |
| const currentYear = new Date().getFullYear(); |
| birthYearInput.max = currentYear; |
| |
| calculateBtn.addEventListener('click', function() { |
| const birthYear = parseInt(birthYearInput.value); |
| |
| |
| if (isNaN(birthYear) || birthYear < 1900 || birthYear > currentYear) { |
| errorMessage.classList.remove('hidden'); |
| resultContainer.classList.add('hidden'); |
| birthYearInput.focus(); |
| return; |
| } |
| |
| errorMessage.classList.add('hidden'); |
| |
| |
| const age = currentYear - birthYear; |
| |
| |
| const months = age * 12; |
| const days = age * 365; |
| const hours = days * 24; |
| |
| |
| ageResult.textContent = `${age} ${age === 1 ? 'year' : 'years'}`; |
| birthYearDisplay.textContent = `Born: ${birthYear}`; |
| currentYearDisplay.textContent = `Current: ${currentYear}`; |
| monthsDisplay.textContent = months; |
| daysDisplay.textContent = days.toLocaleString(); |
| hoursDisplay.textContent = hours.toLocaleString(); |
| |
| |
| resultContainer.classList.remove('hidden'); |
| setTimeout(() => { |
| resultContainer.classList.add('visible'); |
| }, 10); |
| |
| |
| if (age % 10 === 0 && age !== 0) { |
| celebrateMilestone(age); |
| } |
| }); |
| |
| |
| birthYearInput.addEventListener('input', function() { |
| if (errorMessage && !errorMessage.classList.contains('hidden')) { |
| errorMessage.classList.add('hidden'); |
| } |
| }); |
| |
| |
| function celebrateMilestone(age) { |
| const confettiSettings = { |
| particleCount: 100, |
| spread: 70, |
| origin: { y: 0.6 } |
| }; |
| |
| |
| const colors = ['#6366f1', '#8b5cf6', '#ec4899', '#f43f5e', '#f59e0b']; |
| |
| for (let i = 0; i < confettiSettings.particleCount; i++) { |
| const confetti = document.createElement('div'); |
| confetti.style.position = 'absolute'; |
| confetti.style.width = '8px'; |
| confetti.style.height = '8px'; |
| confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)]; |
| confetti.style.borderRadius = '50%'; |
| confetti.style.left = Math.random() * 100 + '%'; |
| confetti.style.top = '-10px'; |
| confetti.style.opacity = '0'; |
| confetti.style.transform = 'translateY(0) rotate(0deg)'; |
| |
| document.body.appendChild(confetti); |
| |
| |
| const animation = confetti.animate([ |
| { |
| opacity: 0, |
| transform: 'translateY(0) rotate(0deg)', |
| top: '-10px' |
| }, |
| { |
| opacity: 1, |
| transform: 'translateY(100px) rotate(180deg)', |
| top: '50%' |
| }, |
| { |
| opacity: 0, |
| transform: 'translateY(200px) rotate(360deg)', |
| top: '100vh' |
| } |
| ], { |
| duration: 2000 + Math.random() * 1000, |
| easing: 'cubic-bezier(0.1, 0.8, 0.3, 1)' |
| }); |
| |
| animation.onfinish = () => confetti.remove(); |
| } |
| |
| |
| const milestone = document.createElement('div'); |
| milestone.textContent = `🎉 Congratulations on ${age} years! 🎉`; |
| milestone.className = 'fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white px-6 py-3 rounded-full shadow-xl z-50 text-indigo-600 font-bold text-center animate-bounce'; |
| document.body.appendChild(milestone); |
| |
| setTimeout(() => { |
| milestone.animate([ |
| { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' }, |
| { opacity: 0, transform: 'translate(-50%, -50%) scale(0.5)' } |
| ], { |
| duration: 500, |
| easing: 'ease-out' |
| }).onfinish = () => milestone.remove(); |
| }, 2000); |
| } |
| }); |
| </script> |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=shambosen/test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> |
| </html> |