I have a switch
statement in which I try to map keyboard shortcuts to a horizontal full page scrolling:
- Space Bar or Page Down or Right Arrow scrolls forward
- Page Up or Left Arrow scrolls backward
- Home or Up Arrow goes to the beginning of the page
- End or Down Arrow scrolls to the end of the page
Here is my attempt, which isn’t working:
switch (event.code) {
case "Space" || "PageDown" || "ArrowRight": {
scrollAmount += window.innerWidth
break
}
case "PageUp" || "ArrowLeft": {
scrollAmount -= window.innerWidth
break
}
case "Home" || "ArrowUp": {
scrollAmount = 0
break
}
case "End" || "ArrowDown": {
scrollAmount = container.scrollWidth
break
}
}
How do I propely use the operators in this case?