Vintage Paper Date Picker - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Vintage Paper Date Picker</title> <style> body { font-family: 'Courier New', monospace; background-color: #f3e5ab; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .date-picker-container { position: relative; width: 300px; text-align: center; } .date-picker { padding: 10px 15px; font-size: 16px; border: 2px solid #8b4513; border-radius: 5px; transition: all 0.3s ease; cursor: pointer; background-color: #fff8dc; color: #8b4513; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .date-picker:hover { border-color: #6b3d12; background-color: #f5deb3; } .calendar { display: none; position: absolute; top: 45px; left: 0; width: 100%; border: 2px solid #8b4513; border-radius: 5px; background-color: #fff8dc; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); animation: fadeIn 0.3s ease; z-index: 1000; } @keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } } .calendar-header { display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #8b4513; color: #fff; border-bottom: 1px solid #8b4513; } .calendar-header button { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; } .calendar-days { display: flex; flex-wrap: wrap; padding: 10px; } .calendar-day { width: 14.28%; padding: 10px; text-align: center; cursor: pointer; transition: background-color 0.3s ease; color: #8b4513; } .calendar-day:hover { background-color: #f5deb3; } .calendar-day.selected { background-color: #8b4513; color: #fff; border-radius: 50%; } </style> </head> <body> <div class="date-picker-container"> <div class="date-picker">Select Date 📜</div> <div class="calendar"> <div class="calendar-header"> <button class="prev-month"><</button> <span class="month-year"></span> <button class="next-month">></button> </div> <div class="calendar-days"></div> </div> </div> <script> document.addEventListener('DOMContentLoaded', () => { const datePicker = document.querySelector('.date-picker'); const calendar = document.querySelector('.calendar'); const monthYear = document.querySelector('.month-year'); const calendarDays = document.querySelector('.calendar-days'); const prevMonth = document.querySelector('.prev-month'); const nextMonth = document.querySelector('.next-month'); let selectedDate = new Date(); let currentMonth = selectedDate.getMonth(); let currentYear = selectedDate.getFullYear(); const monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; const renderCalendar = (month, year) => { calendarDays.innerHTML = ''; monthYear.textContent = `${monthNames[month]} ${year}`; const firstDay = new Date(year, month, 1).getDay(); const daysInMonth = new Date(year, month + 1, 0).getDate(); for (let i = 0; i < firstDay; i++) { calendarDays.innerHTML += `<div class="calendar-day empty"></div>`; } for (let day = 1; day <= daysInMonth; day++) { const dayElement = document.createElement('div'); dayElement.classList.add('calendar-day'); dayElement.textContent = day; if ( day === selectedDate.getDate() && month === selectedDate.getMonth() && year === selectedDate.getFullYear() ) { dayElement.classList.add('selected'); } dayElement.addEventListener('click', () => { selectedDate = new Date(year, month, day); datePicker.textContent = `${monthNames[month]} ${day}, ${year} 📜`; renderCalendar(month, year); calendar.style.display = 'none'; }); calendarDays.appendChild(dayElement); } }; datePicker.addEventListener('click', () => { calendar.style.display = 'block'; renderCalendar(currentMonth, currentYear); }); prevMonth.addEventListener('click', () => { if (currentMonth === 0) { currentMonth = 11; currentYear--; } else { currentMonth--; } renderCalendar(currentMonth, currentYear); }); nextMonth.addEventListener('click', () => { if (currentMonth === 11) { currentMonth = 0; currentYear++; } else { currentMonth++; } renderCalendar(currentMonth, currentYear); }); document.addEventListener('click', (event) => { if (!datePicker.contains(event.target) && !calendar.contains(event.target)) { calendar.style.display = 'none'; } }); }); </script> </body> </html>