Let's replicate Android's notification ignoring animations: <!DOCTYPE html> <html…
- User
Let's replicate Android's notification ignoring animations:
code - Assistant
Let's replicate Android's notification ignoring animations:
body, html {
height: 100%;
font-family: 'Roboto', sans-serif;
background-color: #121212;
color: #ffffff;
overflow: hidden;
user-select: none; /* Prevent text selection during swipe */
}
.lock-screen {
position: relative;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #1f1f1f, #2c2c2c);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transition: transform 0.3s ease, opacity 0.3s ease;
}
.time {
font-size: 64px;
margin-bottom: 5px;
}
.date {
font-size: 20px;
margin-bottom: 20px;
color: #bbbbbb;
}
.notifications {
width: 90%;
max-width: 400px;
}
.notification {
background-color: #1e1e1e;
padding: 15px;
border-radius: 10px;
margin-bottom: 10px;
box-shadow: 0 2px 5px rgba(0,0,0,0.5);
transition: transform 0.3s ease, opacity 0.3s ease;
}
.notification-title {
font-weight: 500;
margin-bottom: 5px;
}
.notification-body {
font-size: 14px;
color: #cccccc;
}
/* Unlock Overlay */
.unlock-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(18, 18, 18, 0.95);
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
z-index: 10;
opacity: 0;
transform: scale(2);
visibility: hidden;
transition: opacity 0.5s ease, transform 0.5s ease, visibility 0.5s;
}
.unlock-overlay.active {
opacity: 1;
transform: scale(1);
visibility: visible;
}
.unlock-title {
font-size: 28px;
margin-bottom: 15px;
}
.pin-input {
display: flex;
gap: 20px;
margin-bottom: 20px;
}
.pin-dot {
font-size: 0px; /* Start with font-size 0 */
opacity: 0;
transition: font-size 0.3s ease, opacity 0.3s ease;
}
.pin-dot.active {
font-size: 20px; /* Target font-size */
opacity: 1;
}
/* Hidden Input Field */
#hiddenPinInput {
position: absolute;
opacity: 0;
pointer-events: none;
height: 0;
width: 0;
}
.unlock-button {
padding: 10px 20px;
font-size: 18px;
background-color: #1e88e5;
border: none;
border-radius: 5px;
color: #ffffff;
cursor: pointer;
transition: background-color 0.3s ease;
}
.unlock-button:hover {
background-color: #1669bb;
}
/* Unlocked Message */
.unlocked-message {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #2e7d32;
padding: 20px 40px;
border-radius: 10px;
font-size: 24px;
color: #ffffff;
display: none;
z-index: 20;
opacity: 0;
transition: opacity 0.3s ease;
}
.unlocked-message.show {
display: block;
opacity: 1;
}
</style>
<!-- Unlock Overlay -->
<div class="unlock-overlay" id="unlockOverlay">
<div class="unlock-title">Enter PIN</div>
<div class="pin-input" id="pinDisplay">
<div class="pin-dot" id="dot1">•</div>
<div class="pin-dot" id="dot2">•</div>
<div class="pin-dot" id="dot3">•</div>
<div class="pin-dot" id="dot4">•</div>
</div>
<input type="text" id="hiddenPinInput" maxlength="4" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" />
<button class="unlock-button" id="submitPin">Unlock</button>
</div>
<!-- Unlocked Message -->
<div class="unlocked-message" id="unlockedMessage">Unlocked</div>
<script>
// Update Time and Date
function updateTime() {
const timeElement = document.getElementById('time');
const dateElement = document.getElementById('date');
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
const ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
minutes = minutes < 10 ? '0' + minutes : minutes;
timeElement.textContent = hours + ':' + minutes;
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
dateElement.textContent = now.toLocaleDateString(undefined, options) + ' ' + ampm;
}
setInterval(updateTime, 1000);
updateTime();
// Swipe Up to Unlock
const lockScreen = document.getElementById('lockScreen');
const unlockOverlay = document.getElementById('unlockOverlay');
const unlockedMessage = document.getElementById('unlockedMessage');
const lockScreenElements = document.querySelectorAll('.lock-screen > *'); // time, date, notifications
let touchStartY = 0;
let touchCurrentY = 0;
let isSwiping = false;
// For desktop (mouse events)
let mouseDown = false;
// Swipe Threshold
const swipeThreshold = 100; // Pixels
// Handle touch events
lockScreen.addEventListener('touchstart', function(e) {
if (e.touches.length === 1) {
touchStartY = e.touches[0].clientY;
isSwiping = true;
}
});
lockScreen.addEventListener('touchmove', function(e) {
if (!isSwiping) return;
const touchY = e.touches[0].clientY;
const deltaY = touchStartY - touchY;
if (deltaY > 0) { // Swiping up
touchCurrentY = touchY;
const swipeDistance = deltaY;
// Calculate opacity based on swipe distance
const opacity = Math.max(1 - swipeDistance / 300, 0.5);
lockScreen.style.transform = `translateY(-${swipeDistance / 2}px)`;
lockScreen.style.opacity = opacity;
}
}, { passive: false });
lockScreen.addEventListener('touchend', function(e) {
if (!isSwiping) return;
const touchEndY = e.changedTouches[0].clientY;
const deltaY = touchStartY - touchEndY;
if (deltaY > swipeThreshold) {
// Trigger unlock overlay
openUnlockOverlay();
} else {
// Revert to original state
lockScreen.style.transform = `translateY(0)`;
lockScreen.style.opacity = 1;
}
isSwiping = false;
});
// Handle mouse events for desktop
lockScreen.addEventListener('mousedown', function(e) {
mouseDown = true;
touchStartY = e.clientY;
isSwiping = true;
});
document.addEventListener('mousemove', function(e) {
if (!isSwiping || !mouseDown) return;
const currentY = e.clientY;
const deltaY = touchStartY - currentY;
if (deltaY > 0) { // Swiping up
touchCurrentY = currentY;
const swipeDistance = deltaY;
// Calculate opacity based on swipe distance
const opacity = Math.max(1 - swipeDistance / 300, 0.5);
lockScreen.style.transform = `translateY(-${swipeDistance / 2}px)`;
lockScreen.style.opacity = opacity;
}
});
document.addEventListener('mouseup', function(e) {
if (!isSwiping) return;
const touchEndY = e.clientY;
const deltaY = touchStartY - touchEndY;
if (deltaY > swipeThreshold) {
// Trigger unlock overlay
openUnlockOverlay();
} else {
// Revert to original state
lockScreen.style.transform = `translateY(0)`;
lockScreen.style.opacity = 1;
}
isSwiping = false;
mouseDown = false;
});
function openUnlockOverlay() {
// Forcibly set opacity to 0 after swipe
lockScreen.style.opacity = 0;
lockScreen.style.transform = `translateY(-100px)`;
// Activate the unlock overlay with smoother transition
unlockOverlay.classList.add('active');
// Clear previous inputs
resetPinDots();
// Focus on hidden input to capture input
hiddenPinInput.focus();
}
// Handle PIN Input with Animated Dots
const hiddenPinInput = document.getElementById('hiddenPinInput');
const pinDots = [
document.getElementById('dot1'),
document.getElementById('dot2'),
document.getElementById('dot3'),
document.getElementById('dot4')
];
function resetPinDots() {
pinDots.forEach(dot => {
dot.classList.remove('active');
});
hiddenPinInput.value = '';
}
hiddenPinInput.addEventListener('input', function(e) {
const value = hiddenPinInput.value;
// Limit to 4 characters
if (value.length > 4) {
hiddenPinInput.value = value.slice(0,4);
}
// Update dots
pinDots.forEach((dot, index) => {
if (index < hiddenPinInput.value.length) {
dot.classList.add('active');
} else {
dot.classList.remove('active');
}
});
});
hiddenPinInput.addEventListener('keydown', function(e) {
if (e.key === 'Backspace') {
// Remove the last active dot
const length = hiddenPinInput.value.length;
if (length > 0) {
pinDots[length - 1].classList.remove('active');
}
} else if (e.key.length === 1 && /\d/.test(e.key) && hiddenPinInput.value.length < 4) {
// Allow digits 0-9 up to 4 characters
} else if (e.key === 'Enter') {
submitPin();
} else {
// Prevent non-digit input
e.preventDefault();
}
});
// Prevent non-digit characters (additional safety)
hiddenPinInput.addEventListener('keypress', function(e) {
const char = String.fromCharCode(e.which);
if (!/[0-9]/.test(char)) {
e.preventDefault();
}
});
// Prevent accidental focus on hidden input
unlockOverlay.addEventListener('click', function(e) {
if (e.target === unlockOverlay) {
hiddenPinInput.focus();
}
});
// Submit PIN
document.getElementById('submitPin').addEventListener('click', submitPin);
function submitPin() {
const enteredPin = hiddenPinInput.value;
if (enteredPin === '1234') {
unlockOverlay.classList.remove('active');
showUnlockedMessage();
} else {
alert('Incorrect PIN. Try again.');
// Clear inputs
resetPinDots();
hiddenPinInput.focus();
}
}
// Show Unlocked Message
function showUnlockedMessage() {
unlockedMessage.classList.add('show');
setTimeout(() => {
unlockedMessage.classList.remove('show');
// Reset lockscreen opacity and transform after unlocking
lockScreen.style.opacity = 1;
lockScreen.style.transform = `translateY(0)`;
}, 2000);
}
// Automatically focus on hidden input when unlock overlay is active
unlockOverlay.addEventListener('transitionend', function() {
if (unlockOverlay.classList.contains('active')) {
hiddenPinInput.focus();
}
});
</script>
Swiping the notification on the left/right should do the Android's animation of notification ignorance then remove the notification... with all other notifications smoothly taking place
To implement Android-like swipe-to-ignore animations for individual notifications, we'll extend your existing code by adding swipe gesture handling to each notification. This feature will allow users to swipe a notification left or right to dismiss it, accompanied by smooth animations.
Here's how we'll achieve this:
Below is the complete updated code with the swipe-to-ignore functionality integrated:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Android-like Lock Screen Simulation</title>
<!-- Import Roboto font from Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<style>
/* Reset default styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body, html {
height: 100%;
font-family: 'Roboto', sans-serif;
background-color: #121212;
color: #ffffff;
overflow: hidden;
user-select: none; /* Prevent text selection during swipe */
}
.lock-screen {
position: relative;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #1f1f1f, #2c2c2c);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transition: transform 0.3s ease, opacity 0.3s ease;
padding: 20px 0;
}
.time {
font-size: 64px;
margin-bottom: 5px;
}
.date {
font-size: 20px;
margin-bottom: 20px;
color: #bbbbbb;
}
.notifications {
width: 90%;
max-width: 400px;
}
.notification {
background-color: #1e1e1e;
padding: 15px;
border-radius: 10px;
margin-bottom: 10px;
box-shadow: 0 2px 5px rgba(0,0,0,0.5);
transition: transform 0.3s ease, opacity 0.3s ease;
position: relative;
touch-action: pan-y;
user-select: none;
}
.notification-title {
font-weight: 500;
margin-bottom: 5px;
}
.notification-body {
font-size: 14px;
color: #cccccc;
}
/* Swipe Overlay */
.swipe-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(30, 30, 30, 0.8);
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
color: #ffffff;
font-size: 24px;
opacity: 0;
transition: opacity 0.3s ease;
pointer-events: none; /* Allow interactions to pass through */
}
.notification.swiping .swipe-overlay {
opacity: 1;
}
/* Unlock Overlay */
.unlock-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(18, 18, 18, 0.95);
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
z-index: 10;
opacity: 0;
transform: scale(2);
visibility: hidden;
transition: opacity 0.5s ease, transform 0.5s ease, visibility 0.5s;
}
.unlock-overlay.active {
opacity: 1;
transform: scale(1);
visibility: visible;
}
.unlock-title {
font-size: 28px;
margin-bottom: 15px;
}
.pin-input {
display: flex;
gap: 20px;
margin-bottom: 20px;
}
.pin-dot {
font-size: 0px; /* Start with font-size 0 */
opacity: 0;
transition: font-size 0.3s ease, opacity 0.3s ease;
}
.pin-dot.active {
font-size: 20px; /* Target font-size */
opacity: 1;
}
/* Hidden Input Field */
#hiddenPinInput {
position: absolute;
opacity: 0;
pointer-events: none;
height: 0;
width: 0;
}
.unlock-button {
padding: 10px 20px;
font-size: 18px;
background-color: #1e88e5;
border: none;
border-radius: 5px;
color: #ffffff;
cursor: pointer;
transition: background-color 0.3s ease;
}
.unlock-button:hover {
background-color: #1669bb;
}
/* Unlocked Message */
.unlocked-message {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #2e7d32;
padding: 20px 40px;
border-radius: 10px;
font-size: 24px;
color: #ffffff;
display: none;
z-index: 20;
opacity: 0;
transition: opacity 0.3s ease;
}
.unlocked-message.show {
display: block;
opacity: 1;
}
</style>
</head>
<body>
<div class="lock-screen" id="lockScreen">
<div class="time" id="time">12:00</div>
<div class="date" id="date">January 1, 2024</div>
<div class="notifications" id="notifications">
<!-- Notification Template -->
<div class="notification">
<div class="swipe-overlay">Ignored</div>
<div class="notification-content">
<div class="notification-title">Email</div>
<div class="notification-body">You have a new message from John.</div>
</div>
</div>
<div class="notification">
<div class="swipe-overlay">Ignored</div>
<div class="notification-content">
<div class="notification-title">Calendar</div>
<div class="notification-body">Meeting at 3 PM today.</div>
</div>
</div>
<!-- Add more notifications as needed -->
</div>
</div>
<!-- Unlock Overlay -->
<div class="unlock-overlay" id="unlockOverlay">
<div class="unlock-title">Enter PIN</div>
<div class="pin-input" id="pinDisplay">
<div class="pin-dot" id="dot1">•</div>
<div class="pin-dot" id="dot2">•</div>
<div class="pin-dot" id="dot3">•</div>
<div class="pin-dot" id="dot4">•</div>
</div>
<input type="text" id="hiddenPinInput" maxlength="4" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" />
<button class="unlock-button" id="submitPin">Unlock</button>
</div>
<!-- Unlocked Message -->
<div class="unlocked-message" id="unlockedMessage">Unlocked</div>
<script>
// Update Time and Date
function updateTime() {
const timeElement = document.getElementById('time');
const dateElement = document.getElementById('date');
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
const ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
minutes = minutes < 10 ? '0' + minutes : minutes;
timeElement.textContent = hours + ':' + minutes;
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
dateElement.textContent = now.toLocaleDateString(undefined, options) + ' ' + ampm;
}
setInterval(updateTime, 1000);
updateTime();
// Swipe Up to Unlock
const lockScreen = document.getElementById('lockScreen');
const unlockOverlay = document.getElementById('unlockOverlay');
const unlockedMessage = document.getElementById('unlockedMessage');
const lockScreenElements = document.querySelectorAll('.lock-screen > *'); // time, date, notifications
let touchStartY = 0;
let touchCurrentY = 0;
let isSwiping = false;
// For desktop (mouse events)
let mouseDown = false;
// Swipe Threshold
const swipeThreshold = 100; // Pixels
// Handle touch events
lockScreen.addEventListener('touchstart', function(e) {
if (e.touches.length === 1) {
touchStartY = e.touches[0].clientY;
isSwiping = true;
}
});
lockScreen.addEventListener('touchmove', function(e) {
if (!isSwiping) return;
const touchY = e.touches[0].clientY;
const deltaY = touchStartY - touchY;
if (deltaY > 0) { // Swiping up
touchCurrentY = touchY;
const swipeDistance = deltaY;
// Calculate opacity based on swipe distance
const opacity = Math.max(1 - swipeDistance / 300, 0.5);
lockScreen.style.transform = `translateY(-${swipeDistance / 2}px)`;
lockScreen.style.opacity = opacity;
}
}, { passive: false });
lockScreen.addEventListener('touchend', function(e) {
if (!isSwiping) return;
const touchEndY = e.changedTouches[0].clientY;
const deltaY = touchStartY - touchEndY;
if (deltaY > swipeThreshold) {
// Trigger unlock overlay
openUnlockOverlay();
} else {
// Revert to original state
lockScreen.style.transform = `translateY(0)`;
lockScreen.style.opacity = 1;
}
isSwiping = false;
});
// Handle mouse events for desktop
lockScreen.addEventListener('mousedown', function(e) {
mouseDown = true;
touchStartY = e.clientY;
isSwiping = true;
});
document.addEventListener('mousemove', function(e) {
if (!isSwiping || !mouseDown) return;
const currentY = e.clientY;
const deltaY = touchStartY - currentY;
if (deltaY > 0) { // Swiping up
touchCurrentY = currentY;
const swipeDistance = deltaY;
// Calculate opacity based on swipe distance
const opacity = Math.max(1 - swipeDistance / 300, 0.5);
lockScreen.style.transform = `translateY(-${swipeDistance / 2}px)`;
lockScreen.style.opacity = opacity;
}
});
document.addEventListener('mouseup', function(e) {
if (!isSwiping) return;
const touchEndY = e.clientY;
const deltaY = touchStartY - touchEndY;
if (deltaY > swipeThreshold) {
// Trigger unlock overlay
openUnlockOverlay();
} else {
// Revert to original state
lockScreen.style.transform = `translateY(0)`;
lockScreen.style.opacity = 1;
}
isSwiping = false;
mouseDown = false;
});
function openUnlockOverlay() {
// Forcibly set opacity to 0 after swipe
lockScreen.style.opacity = 0;
lockScreen.style.transform = `translateY(-100px)`;
// Activate the unlock overlay with smoother transition
unlockOverlay.classList.add('active');
// Clear previous inputs
resetPinDots();
// Focus on hidden input to capture input
hiddenPinInput.focus();
}
// Handle PIN Input with Animated Dots
const hiddenPinInput = document.getElementById('hiddenPinInput');
const pinDots = [
document.getElementById('dot1'),
document.getElementById('dot2'),
document.getElementById('dot3'),
document.getElementById('dot4')
];
function resetPinDots() {
pinDots.forEach(dot => {
dot.classList.remove('active');
});
hiddenPinInput.value = '';
}
hiddenPinInput.addEventListener('input', function(e) {
const value = hiddenPinInput.value;
// Limit to 4 characters
if (value.length > 4) {
hiddenPinInput.value = value.slice(0,4);
}
// Update dots
pinDots.forEach((dot, index) => {
if (index < hiddenPinInput.value.length) {
dot.classList.add('active');
} else {
dot.classList.remove('active');
}
});
});
hiddenPinInput.addEventListener('keydown', function(e) {
if (e.key === 'Backspace') {
// Remove the last active dot
const length = hiddenPinInput.value.length;
if (length > 0) {
pinDots[length - 1].classList.remove('active');
}
} else if (e.key.length === 1 && /\d/.test(e.key) && hiddenPinInput.value.length < 4) {
// Allow digits 0-9 up to 4 characters
} else if (e.key === 'Enter') {
submitPin();
} else {
// Prevent non-digit input
e.preventDefault();
}
});
// Prevent non-digit characters (additional safety)
hiddenPinInput.addEventListener('keypress', function(e) {
const char = String.fromCharCode(e.which);
if (!/[0-9]/.test(char)) {
e.preventDefault();
}
});
// Prevent accidental focus on hidden input
unlockOverlay.addEventListener('click', function(e) {
if (e.target === unlockOverlay) {
hiddenPinInput.focus();
}
});
// Submit PIN
document.getElementById('submitPin').addEventListener('click', submitPin);
function submitPin() {
const enteredPin = hiddenPinInput.value;
if (enteredPin === '1234') {
unlockOverlay.classList.remove('active');
showUnlockedMessage();
} else {
alert('Incorrect PIN. Try again.');
// Clear inputs
resetPinDots();
hiddenPinInput.focus();
}
}
// Show Unlocked Message
function showUnlockedMessage() {
unlockedMessage.classList.add('show');
setTimeout(() => {
unlockedMessage.classList.remove('show');
// Reset lockscreen opacity and transform after unlocking
lockScreen.style.opacity = 1;
lockScreen.style.transform = `translateY(0)`;
}, 2000);
}
// Automatically focus on hidden input when unlock overlay is active
unlockOverlay.addEventListener('transitionend', function() {
if (unlockOverlay.classList.contains('active')) {
hiddenPinInput.focus();
}
});
// Swipe-to-Dismiss Functionality for Notifications
const notificationsContainer = document.getElementById('notifications');
const notifications = document.querySelectorAll('.notification');
notifications.forEach(notification => {
let startX = 0;
let startY = 0;
let currentX = 0;
let currentY = 0;
let isSwipingNotification = false;
let swipeDirection = null; // 'left' or 'right'
// Thresholds
const swipeThresholdX = 100; // Minimum swipe distance on X-axis
const swipeThresholdY = 50; // Maximum swipe distance on Y-axis to distinguish from vertical scroll
// Touch Events
notification.addEventListener('touchstart', function(e) {
if (e.touches.length === 1) {
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
isSwipingNotification = true;
notification.classList.add('swiping');
}
});
notification.addEventListener('touchmove', function(e) {
if (!isSwipingNotification) return;
const touch = e.touches[0];
currentX = touch.clientX;
currentY = touch.clientY;
const deltaX = currentX - startX;
const deltaY = currentY - startY;
if (Math.abs(deltaY) > swipeThresholdY) {
// Not a horizontal swipe
isSwipingNotification = false;
notification.classList.remove('swiping');
return;
}
// Determine swipe direction
if (deltaX > 0) {
swipeDirection = 'right';
} else {
swipeDirection = 'left';
}
// Move the notification
notification.style.transform = `translateX(${deltaX}px)`;
// Optionally, rotate slightly based on swipe
// notification.style.transform += ` rotate(${deltaX * 0.1}deg)`;
// Show swipe overlay if swiped enough
if (Math.abs(deltaX) > swipeThresholdX / 2) {
notification.querySelector('.swipe-overlay').textContent = swipeDirection === 'left' ? 'Ignored' : 'Ignored';
}
}, { passive: false });
notification.addEventListener('touchend', function(e) {
if (!isSwipingNotification) return;
isSwipingNotification = false;
const deltaX = currentX - startX;
if (Math.abs(deltaX) > swipeThresholdX) {
// Swipe is confirmed
// Animate the notification out of view
const direction = deltaX > 0 ? 1 : -1;
notification.style.transition = 'transform 0.3s ease, opacity 0.3s ease';
notification.style.transform = `translateX(${direction * window.innerWidth}px)`;
notification.style.opacity = '0';
// Remove the notification after the animation
notification.addEventListener('transitionend', function() {
notification.remove();
// Optionally, adjust remaining notifications
});
} else {
// Not a valid swipe, revert back
notification.style.transform = `translateX(0)`;
notification.style.transition = 'transform 0.3s ease, opacity 0.3s ease';
notification.querySelector('.swipe-overlay').textContent = 'Ignored';
notification.addEventListener('transitionend', function() {
notification.style.transition = '';
notification.classList.remove('swiping');
}, { once: true });
}
});
// Mouse Events for Desktop
notification.addEventListener('mousedown', function(e) {
startX = e.clientX;
startY = e.clientY;
isSwipingNotification = true;
swipeDirection = null;
notification.classList.add('swiping');
// Mouse move and up are handled on the document
});
function onMouseMove(e) {
if (!isSwipingNotification) return;
currentX = e.clientX;
currentY = e.clientY;
const deltaX = currentX - startX;
const deltaY = currentY - startY;
if (Math.abs(deltaY) > swipeThresholdY) {
// Not a horizontal swipe
isSwipingNotification = false;
notification.classList.remove('swiping');
return;
}
// Determine swipe direction
if (deltaX > 0) {
swipeDirection = 'right';
} else {
swipeDirection = 'left';
}
// Move the notification
notification.style.transform = `translateX(${deltaX}px)`;
// Optionally, rotate slightly based on swipe
// notification.style.transform += ` rotate(${deltaX * 0.1}deg)`;
// Show swipe overlay if swiped enough
if (Math.abs(deltaX) > swipeThresholdX / 2) {
notification.querySelector('.swipe-overlay').textContent = swipeDirection === 'left' ? 'Ignored' : 'Ignored';
}
}
function onMouseUp(e) {
if (!isSwipingNotification) return;
isSwipingNotification = false;
const deltaX = currentX - startX;
if (Math.abs(deltaX) > swipeThresholdX) {
// Swipe is confirmed
// Animate the notification out of view
const direction = deltaX > 0 ? 1 : -1;
notification.style.transition = 'transform 0.3s ease, opacity 0.3s ease';
notification.style.transform = `translateX(${direction * window.innerWidth}px)`;
notification.style.opacity = '0';
// Remove the notification after the animation
notification.addEventListener('transitionend', function() {
notification.remove();
// Optionally, adjust remaining notifications
}, { once: true });
} else {
// Not a valid swipe, revert back
notification.style.transform = `translateX(0)`;
notification.style.transition = 'transform 0.3s ease, opacity 0.3s ease';
notification.querySelector('.swipe-overlay').textContent = 'Ignored';
notification.addEventListener('transitionend', function() {
notification.style.transition = '';
notification.classList.remove('swiping');
}, { once: true });
}
// Remove the global event listeners
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
}
notification.addEventListener('mousedown', function(e) {
onMouseMove = onMouseMove.bind(this, e);
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
});
});
</script>
</body>
</html>
CSS Enhancements:
.swipe-overlay: Added an overlay that appears during the swipe gesture to mimic the 'Ignored' feedback..notification.swiping .swipe-overlay: Controls the visibility of the swipe overlay when a swipe is in progress.HTML Structure:
.notification now contains a .swipe-overlay div that displays the "Ignored" text during the swipe..notification-content div for better structure and maintainability.JavaScript Enhancements:
Responsiveness: The swipe thresholds and animations are designed to work across different screen sizes. However, you can adjust the swipeThresholdX and swipeThresholdY values in the JavaScript to better fit your needs.
Accessibility: Ensure that the swipe-to-dismiss functionality is accessible, especially for users who rely on keyboard navigation or assistive technologies. You might consider adding alternative methods for dismissing notifications.
Performance: Removing elements from the DOM after animations helps in managing memory and ensures that the interface remains responsive, especially when dealing with a large number of notifications.
Customization: You can customize the "Ignored" text, colors, and animation speeds to better match your desired aesthetic or user experience.
Touch Devices: On a touchscreen device, try swiping a notification left or right. The notification should follow your finger, display the "Ignored" overlay, and then slide out of view, removing itself from the list.
Desktop Browsers: Click and drag a notification left or right using your mouse. The same behavior as on touch devices should occur.
Invalid Swipes: If you swipe less than the swipeThresholdX, the notification should return to its original position, indicating that the swipe wasn't sufficient to dismiss it.
Unlock Overlay and PIN Entry: Ensure that the existing lock screen functionality remains unaffected by these changes and operates smoothly alongside the new swipe-to-dismiss feature.
With these enhancements, your lock screen simulation now closely mimics Android's notification behavior, allowing users to intuitively swipe notifications away with smooth animations and feedback. Feel free to tweak the thresholds, animations, and styles further to align with your specific requirements or preferences.
Not yet included in a published release.