반응형
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 = Math.round(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((element, index)=> {
if(scrollTop >= element.offsetTop -2){
document.querySelectorAll("#parallax__dot li").forEach( li => {
li.classList.remove("active");
});
document.querySelector("#parallax__dot li:nth-child("+(index+1)+")").classList.add("active");
}
})
});
패럴랙스 효과
01 Section1 단순하게 살아라. 현대인은 쓸데없는 절차와 일 때문에 얼마나 복잡한 삶을 살아가는가? 02 Section2 돈이란 바닷물과도 같다. 그것은 마시면 마실수록 목이 말라진다. 03 Section3 먼저 자신
jiseonpack.github.io
반응형
'Script Sample > Parallax Effect' 카테고리의 다른 글
Parallax Effect06 - 텍스트 효과 (0) | 2022.03.08 |
---|---|
Parallax Effect05 - 이질감 효과 (0) | 2022.03.08 |
Parallax Effect04 - 나타나기 (0) | 2022.03.08 |
Parallax Effect03 - 숨김 메뉴 (0) | 2022.03.08 |
Parallax Effect01 - 메뉴 이동 (0) | 2022.03.08 |