<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern Time Picker</title>
<style>
:root {
--item-height: 60px;
--wheel-height: calc(var(--item-height) * 5); /* Show 5 items at a time */
--orange-color: #FF9500;
}
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;800&display=swap');
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-color: #000000;
color: #FFFFFF;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
overflow: hidden;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* 🧩 1. Main Interface Layout */
.main-container {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
height: 100vh;
padding: 40px 0;
box-sizing: border-box;
}
/* 🔧 2. Dual Scroll Wheel Time Picker */
.time-picker-assembly {
display: flex;
justify-content: center;
align-items: center;
gap: 5px;
margin-top: auto; /* Push to vertical center */
}
.wheel-container {
position: relative;
height: var(--wheel-height);
width: 100px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 12px;
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
perspective: 1200px; /* For 3D curved effect */
}
/* Fading gradients */
.wheel-container::before,
.wheel-container::after {
content: '';
position: absolute;
left: 0;
right: 0;
height: calc(var(--wheel-height) / 2 - var(--item-height) / 2);
z-index: 2;
pointer-events: none;
}
.wheel-container::before {
top: 0;
background: linear-gradient(to bottom, #000000 40%, transparent);
}
.wheel-container::after {
bottom: 0;
background: linear-gradient(to top, #000000 40%, transparent);
}
/* The actual scrollable wheel */
.wheel {
height: 100%;
overflow-y: scroll;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.wheel::-webkit-scrollbar {
display: none; /* Chrome, Safari, and Opera */
}
.wheel-item {
height: var(--item-height);
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
font-weight: 400;
transition: transform 0.2s ease-out, opacity 0.2s ease-out;
opacity: 0.3;
transform: rotateX(45deg) scale(0.8);
}
/* Style for the selected (center) value */
.wheel-item.selected {
font-size: 36px;
font-weight: 800;
opacity: 1;
color: var(--orange-color);
transform: rotateX(0deg) scale(1.1);
}
.time-separator {
font-size: 36px;
font-weight: 800;
padding: 0 10px;
color: var(--orange-color);
}
/* 3.2. Main Lock Button */
.lock-button {
width: calc(100% - 40px);
max-width: 400px;
padding: 18px;
font-size: 18px;
font-weight: 700;
color: #FFFFFF;
background-color: var(--orange-color);
border: none;
border-radius: 16px;
cursor: pointer;
margin-top: auto; /* Push to bottom */
transition: transform 0.1s ease, background-color 0.2s ease;
}
.lock-button:active {
transform: scale(0.98);
}
/* Lock Confirmation Pop-Up */
.popup-container {
position: fixed;
bottom: 0;
left: 0;
right: 0;
top: 0;
background: rgba(0, 0, 0, 0.4);
display: flex;
justify-content: center;
align-items: flex-end;
z-index: 100;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s ease-in-out;
}
.popup-container.visible {
opacity: 1;
pointer-events: auto;
}
.popup-content {
background: rgba(30, 30, 30, 0.75);
backdrop-filter: blur(25px);
-webkit-backdrop-filter: blur(25px);
width: 100%;
max-width: 480px;
padding: 20px;
box-sizing: border-box;
border-top-left-radius: 24px;
border-top-right-radius: 24px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-bottom: none;
text-align: center;
transform: translateY(100%);
transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.popup-container.visible .popup-content {
transform: translateY(0);
}
.popup-content h2 {
margin-top: 10px;
margin-bottom: 5px;
font-weight: 700;
}
.popup-content p {
margin-bottom: 25px;
color: rgba(255, 255, 255, 0.7);
}
#confirm-time {
font-weight: 700;
color: var(--orange-color);
}
.popup-buttons {
display: flex;
gap: 15px;
}
.popup-buttons button {
flex: 1;
padding: 16px;
border-radius: 12px;
border: none;
font-size: 16px;
font-weight: 700;
cursor: pointer;
transition: transform 0.1s ease;
}
.popup-buttons button:active {
transform: scale(0.97);
}
#cancel-button {
background: rgba(255, 255, 255, 0.15);
color: #FFFFFF;
}
#confirm-lock-button {
background: var(--orange-color);
color: #FFFFFF;
}
</style>
</head>
<body>
<div class="main-container">
<div class="time-picker-assembly">
<!-- Hours Wheel -->
<div class="wheel-container">
<div class="wheel" id="hours-wheel"></div>
</div>
<div class="time-separator">:</div>
<!-- Minutes Wheel -->
<div class="wheel-container">
<div class="wheel" id="minutes-wheel"></div>
</div>
</div>
<button class="lock-button" id="lock-button">Lock</button>
</div>
<!-- Lock Confirmation Pop-Up -->
<div class="popup-container" id="popup-container">
<div class="popup-content">
<h2>Confirm Lock</h2>
<p>Set timer for <strong id="confirm-time">00:00</strong>?</p>
<div class="popup-buttons">
<button id="cancel-button">Cancel</button>
<button id="confirm-lock-button">Confirm</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const ITEM_HEIGHT = 60; // Must match --item-height in CSS
const PADDING_ITEMS = 2; // (container height / item height - 1) / 2
const hoursWheel = document.getElementById('hours-wheel');
const minutesWheel = document.getElementById('minutes-wheel');
const lockButton = document.getElementById('lock-button');
const popup = document.getElementById('popup-container');
const confirmTimeEl = document.getElementById('confirm-time');
const cancelButton = document.getElementById('cancel-button');
const confirmLockButton = document.getElementById('confirm-lock-button');
let scrollEndTimer;
// --- Haptic Feedback ---
function vibrate() {
if (window.navigator && window.navigator.vibrate) {
navigator.vibrate(5); // Vibrate for 5ms
}
}
// --- Populate Wheels ---
function populateWheel(wheel, max, step = 1) {
// Add top padding
for (let i = 0; i < PADDING_ITEMS; i++) {
const el = document.createElement('div');
el.className = 'wheel-item';
wheel.appendChild(el);
}
// Add actual values
for (let i = 0; i < max; i += step) {
const el = document.createElement('div');
el.className = 'wheel-item';
el.textContent = String(i).padStart(2, '0');
wheel.appendChild(el);
}
// Add bottom padding
for (let i = 0; i < PADDING_ITEMS; i++) {
const el = document.createElement('div');
el.className = 'wheel-item';
wheel.appendChild(el);
}
}
// --- Update Visuals on Scroll ---
function updateWheelStyles(wheel) {
const scrollTop = wheel.scrollTop;
const centerIndex = Math.round(scrollTop / ITEM_HEIGHT) + PADDING_ITEMS;
let didVibrate = false;
wheel.querySelectorAll('.wheel-item').forEach((item, index) => {
if (index === centerIndex) {
if (!item.classList.contains('selected')) {
item.classList.add('selected');
if (!didVibrate) {
vibrate();
didVibrate = true;
}
}
} else {
item.classList.remove('selected');
}
});
}
// --- Auto-Snap to Nearest Value ---
function setupScrollListener(wheel) {
let lastSelectedIndex = -1;
wheel.addEventListener('scroll', () => {
clearTimeout(scrollEndTimer);
// Update styles while scrolling
const currentIndex = Math.round(wheel.scrollTop / ITEM_HEIGHT);
if (currentIndex !== lastSelectedIndex) {
updateWheelStyles(wheel);
lastSelectedIndex = currentIndex;
}
// Set a timer to detect scroll end
scrollEndTimer = setTimeout(() => {
const scrollTop = wheel.scrollTop;
const index = Math.round(scrollTop / ITEM_HEIGHT);
const targetScrollTop = index * ITEM_HEIGHT;
wheel.scrollTo({
top: targetScrollTop,
behavior: 'smooth'
});
}, 100); // Adjust timeout for desired sensitivity
}, { passive: true });
}
// --- Get Selected Time ---
function getSelectedTime() {
const hoursIndex = Math.round(hoursWheel.scrollTop / ITEM_HEIGHT);
const minutesIndex = Math.round(minutesWheel.scrollTop / ITEM_HEIGHT);
const hours = String(hoursIndex).padStart(2, '0');
const minutes = String(minutesIndex).padStart(2, '0');
return { hours, minutes };
}
// --- Pop-Up Logic ---
lockButton.addEventListener('click', () => {
const { hours, minutes } = getSelectedTime();
confirmTimeEl.textContent = `${hours}:${minutes}`;
popup.classList.add('visible');
});
function closePopup() {
popup.classList.remove('visible');
}
cancelButton.addEventListener('click', closePopup);
confirmLockButton.addEventListener('click', () => {
// Here you would implement the actual lock logic
alert(`Timer locked for ${confirmTimeEl.textContent}!`);
closePopup();
});
// Also close if clicking on the background
popup.addEventListener('click', (e) => {
if (e.target === popup) {
closePopup();
}
});
// --- Initialization ---
populateWheel(hoursWheel, 25); // 0-24
populateWheel(minutesWheel, 60); // 0-59
setupScrollListener(hoursWheel);
setupScrollListener(minutesWheel);
// Set initial styles
updateWheelStyles(hoursWheel);
updateWheelStyles(minutesWheel);
});
</script>
</body>
</html>