I am trying to create a parallax effect on the scroll. "Po Ta To" have to scroll at different speeds. however it isn't working.
window.addEventListener("scroll", function(e) {
const target = document.querySelectorAll('.parallax');
var index = 0,
length = target.length;
for (index; index < length; index++) {
var pos = window.pageYOffset * target[index].dataset.speed;
target[index].style.transform = 'translate3d(0px, ' + pos + 'px, 0px)';
}
});
* {
margin: 0px;
padding: 0px;
width: 100%;
font-family: Montserrat;
height: 200vh;
}
section {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
ul {
height: 30vh;
text-align: center;
white-space: nowrap;
}
li {
font-size: 100px;
font-weight: bold;
text-align: center;
display: inline;
}
<section>
<ul>
<li class="parallax" data-speed="2">PO</li>
<li class="parallax" data-speed="1.5">TA</li>
<li class="parallax" data-speed="2.3">TO</li>
</ul>
</section>