Header scroll-animation : 스크롤 내리면 Background 색상 변경

오늘의 정리 1. 스크롤을 내릴 때 transparent => 색상이 변하는 기능을 구현하기 2. Coding const header = document.querySelector(“#header”); const headerHeight = header.getBoundingClientRect().height; window.addEventListener(“scroll”, () => { if (window.scrollY > headerHeight) { header.setAttribute(“style”, “background: white;”); } else { header.setAttribute(“style”, “background: transparent;”); } }); 3. 설명 해당 DOM의 높이를 변수로 잡는다. – getBoundingClientRect().height; window에 scroll 이벤트를 더한 […]

Read more