let's try this bitch

This commit is contained in:
sakrecoer 2025-06-30 01:17:52 +02:00
parent d08c3cc0a1
commit f31b7d282d

View file

@ -34,24 +34,45 @@
</style> </style>
<script> <script>
// Only run on mobile // Wait for the page to fully load
if (window.matchMedia("(max-width: 768px)").matches) { document.addEventListener('DOMContentLoaded', () => {
let scrollTimeout; // Check if mobile AND touch device (dual verification)
const html = document.documentElement; const isMobile = window.matchMedia("(max-width: 768px)").matches;
const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
window.addEventListener('scroll', () => { if (isMobile && isTouch) {
// Add color mode const html = document.documentElement;
html.classList.add('color-mode'); let scrollTimeout;
let lastScrollTime = 0;
// Reset timeout on scroll // Handle both touch AND scroll for compatibility
clearTimeout(scrollTimeout); window.addEventListener('scroll', handleScroll, { passive: true });
window.addEventListener('touchmove', handleScroll, { passive: true });
// Revert to grayscale after 1 second of no scrolling function handleScroll() {
scrollTimeout = setTimeout(() => { const now = Date.now();
html.classList.remove('color-mode');
}, 1000); // Throttle events to improve performance
}, { passive: true }); // Optimized for performance if (now - lastScrollTime < 50) return; // 50ms throttle
} lastScrollTime = now;
html.classList.add('color-mode');
clearTimeout(scrollTimeout);
// Longer delay for touch momentum (2 seconds)
scrollTimeout = setTimeout(() => {
html.classList.remove('color-mode');
}, 2000);
}
// Reset on touch end (for immediate feedback)
window.addEventListener('touchend', () => {
scrollTimeout = setTimeout(() => {
html.classList.remove('color-mode');
}, 500); // Shorter delay after touch ends
}, { passive: true });
}
});
</script> </script>
{{ partial "body/now.html" . }} {{ partial "body/now.html" . }}