티스토리 뷰
document.querySelectorAll("#parallax__dot a").forEach(el => {
el.addEventListener("click", e => {
e.preventDefault();
// window.scroll(0, 1000);
// window.scroll({left:0, top: 1000 });
// window.scroll({left:0, top: 1000, behavior: "smooth" });
// window.scrollTo(0, 1000);
// window.scrollTO({left:0, top: 1000 });
// window.scrollTo({left:0, top: 1000, behavior: "smooth" });
// window.scrollBy(0, 1000);
// window.scrollBy({left:0, top: 1000 });
// window.scrollBy({left:0, top: 1000, behavior: "smooth" });
document.querySelector(el.getAttribute("href")).scrollIntoView({behavior: "smooth"});
})
})
window.addEventListener("scroll", () => {
let scrollTop = window.screenY || window.pageYOffset || document.documentElement.scrollTop;
document.querySelector(".scrollTop span").innerText = scrollTop;
// for(let i=1; i<=9; i++){
// if(scrollTop >= document.getElementById("section"+i).offsetTop - 2){
// document.querySelectorAll("#parallax__dot li").forEach(li => {
// li.classList.remove("active");
// })
// document.querySelector("#parallax__dot li:nth-child("+i+")").classList.add("active");
// }
// }
//forEach
document.querySelectorAll(".content__item").forEach((item,i) => {
if(scrollTop >= item.offsetTop -2){
document.querySelectorAll("#parallax__dot ul li").forEach(li => {
li.classList.remove("active");
});
document.querySelector(`#parallax__dot ul li:nth-child(${i+1})`).classList.add("active");
}
});
});
'Script Sample > Parallax Effect' 카테고리의 다른 글
Parallax Effect - 텍스트 효과 (0) | 2022.04.14 |
---|---|
Parallax Effect - 이질감 효과 (0) | 2022.04.14 |
Parallax Effect - 나타나기 효과 (0) | 2022.04.14 |
Parallax Effect - 숨김 메뉴 (0) | 2022.04.14 |
Parallax Effect - 메뉴 이동 (0) | 2022.04.14 |
댓글
© 2018 webstoryboy