I have a horizontal scrolling website where I want to take the users’ Y-scrolling input to convert it into X-scrolling. The website already works perfectly when using a trackpad and scrolling on the X axis, so I just want it to work the other way around. Thanks!
This is what I’m trying to workshop but I’m very new to this and it’s probably very wrong:
<script>
let invertedscroll = window.ScrollY;
window.addEventListener('scroll', (scrollY) );
function invertscroll (scrollY) {
window.scrollY = window.scrollX;
}
</script>
2
Answers
Use window.scrollTo and invertScroll instead of "scrollY" which is undefined in your implementation:
Another solution would be to set
scrollLeft
directly to the<html>
when scrolling using thewheel
event.And don’t forget to call
event.preventDefault()
to prevent vertical scroll