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,7 +67,12 @@ 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', () => {
|
||||||
|
if (resizeTimeout) clearTimeout(resizeTimeout);
|
||||||
|
|
||||||
|
resizeTimeout = setTimeout(() => {
|
||||||
const currentWidth = window.innerWidth;
|
const currentWidth = window.innerWidth;
|
||||||
const lgBreakpoint = 1024;
|
const lgBreakpoint = 1024;
|
||||||
|
|
||||||
@@ -82,6 +87,7 @@ document.addEventListener('alpine:init', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastWidth = currentWidth;
|
lastWidth = currentWidth;
|
||||||
|
}, 150);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Theme setup
|
// Theme setup
|
||||||
|
|||||||
Reference in New Issue
Block a user