perf(ui): debounce window resize event for sidebar responsiveness
Debounce the window resize event listener with a 150ms timeout to prevent excessive executions, improving performance during window resizing.
This commit is contained in:
@@ -67,21 +67,27 @@ document.addEventListener('alpine:init', () => {
|
|||||||
|
|
||||||
// Handle responsive sidebar transitions
|
// Handle responsive sidebar transitions
|
||||||
let lastWidth = window.innerWidth;
|
let lastWidth = window.innerWidth;
|
||||||
|
let resizeTimeout = null;
|
||||||
|
|
||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
const currentWidth = window.innerWidth;
|
if (resizeTimeout) clearTimeout(resizeTimeout);
|
||||||
const lgBreakpoint = 1024;
|
|
||||||
|
|
||||||
// Desktop -> Mobile: Auto-close sidebar to prevent overlay blocking screen
|
resizeTimeout = setTimeout(() => {
|
||||||
if (lastWidth >= lgBreakpoint && currentWidth < lgBreakpoint) {
|
const currentWidth = window.innerWidth;
|
||||||
this.sidebarOpen = false;
|
const lgBreakpoint = 1024;
|
||||||
}
|
|
||||||
|
// Desktop -> Mobile: Auto-close sidebar to prevent overlay blocking screen
|
||||||
// Mobile -> Desktop: Auto-open sidebar (restore standard desktop layout)
|
if (lastWidth >= lgBreakpoint && currentWidth < lgBreakpoint) {
|
||||||
if (lastWidth < lgBreakpoint && currentWidth >= lgBreakpoint) {
|
this.sidebarOpen = false;
|
||||||
this.sidebarOpen = true;
|
}
|
||||||
}
|
|
||||||
|
// Mobile -> Desktop: Auto-open sidebar (restore standard desktop layout)
|
||||||
lastWidth = currentWidth;
|
if (lastWidth < lgBreakpoint && currentWidth >= lgBreakpoint) {
|
||||||
|
this.sidebarOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastWidth = currentWidth;
|
||||||
|
}, 150);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Theme setup
|
// Theme setup
|
||||||
|
|||||||
Reference in New Issue
Block a user