我有一个从汉堡打开的简单导航菜单。当它打开时,如何防止屏幕上的所有滚动?导航栏是 100vh,我想防止在它打开时滚动经过它?
到目前为止导航菜单的 Js(没有滚动功能)
const navSlide = () => {
const burger = document.getElementById('burger')
const nav = document.getElementById('nav')
const navLinks = document.querySelectorAll('.nav-links li')
burger.addEventListener('click', () => {
nav.classList.toggle('nav-active')
navLinks.forEach( (link, index) => {
if (link.style.animation) {
link.style.animation = ''
} else {
link.style.animation = `navLinkFade 0.7s ease forwards ${index / 7 + 0.4}s`
}
})
burger.classList.toggle('toggle')
})
}
navSlide()
Run Code Online (Sandbox Code Playgroud) This error is in the console and it prevents the app from working, I cant find the bug at all if anyone could help? Its a MERN application
The code in question
export const getPosts = () => async (dispatch) => {
try {
const { data } = await api.fetchPosts();
dispatch({ type: 'FETCH_ALL', payload: data });
} catch (error) {
console.log(error.message);
}
};
Run Code Online (Sandbox Code Playgroud)
VSC is telling me await doesn't effect this kind of expression, which it should as fetchPosts …