본문 바로가기
JavaScript/Next.js

[Next.js] body태그에 overflow-x:hidden 을 사용할 시 문제점

by 봉이로그 2023. 3. 27.
// src/styles/globals.css

body {
	overflow-x:hidden;
}

x축 (가로) 스크롤을 없애기 위해 body에 CSS로 overflow-x:hidden을 사용할경우

window.addEventListener('scroll', func) 가 정상적으로 작동이 되지 않는다.

document.getElementById(__next).addEventListener // 안됨
document.body.addEventListener // 안됨

이러한 방법을 사용해봤지만, 적용이 안되었다.

 

결론은 위처럼 사용할시 scroll event 함수를 줄수가 없다.

 

body::-webkit-scrollbar {
	display:none;
}

이렇게 scrollbar를 없애는 방법이 있다.

 

Reference

https://github.com/vercel/next.js/issues/6132

 

how can i handle window scroll event · Issue #6132 · vercel/next.js

Hi. I worked on project with nextjs and i need to set scroll event handler for window. How can i do it ?

github.com

https://github.com/vercel/next.js/discussions/18299

 

Window scroll event not fired · vercel/next.js · Discussion #18299

Bug report Describe the bug Window scroll event are not fired. To Reproduce Steps to reproduce the behavior, please provide code snippets or a repository: const handleScroll = (e) => { console.log(...

github.com

 

'JavaScript > Next.js' 카테고리의 다른 글

[Next.js] HTTP Security headers 적용  (0) 2023.03.30