I have implemented a hamburger menu for mobile views on my website, and I want to prevent the background website content from being scrollable when the menu is open. The only relevant code I found was the following:
function toggleMenu() {
menuOpen = !menuOpen;
}
$: {
if (typeof window !== 'undefined') {
document.body.style.overflow = menuOpen ? 'hidden' : '';
}
}
Is there a more idiomatic way to achieve this in Svelte?
Top comments (0)