This seems to have been asked before without a sufficient answer. I have absolutely no knowledge of how to do this (including no plugins). I want my website to scroll horizontally when I actively scroll down vertically.
Some examples of what I mean: http://hotdot.pro/en/ and http://mashup.ikm.gda.pl/
To be clear, I don't care about the parallax effect that both of these websites utilize. I just want to scroll horizontally.
Thanks!
Click File > Options. On the Advanced tab, scroll to the Display section. Select Show horizontal scroll bar and Show vertical scroll bar, and then click OK.
Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.
Scroll horizontally using a keyboard and mousePress and hold SHIFT. Scroll up or down using your mouse wheel (or another vertical scrolling function of your mouse).
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
This can be solved in native JavaScript, without any library.
function transformScroll(event) {
if (!event.deltaY) {
return;
}
event.currentTarget.scrollLeft += event.deltaY + event.deltaX;
event.preventDefault();
}
var element = document.scrollingElement || document.documentElement;
element.addEventListener('wheel', transformScroll);
While this solution does not lean on any library, it also takes other usage scenario's into account. When scrolling on a touchpad for example, the other solutions that lean on a single delta value all fall apart.
There are always multiple ways of scrolling with an input device. Laptops have touchpads, phones have touchscreens, mouses have scroll wheels. On top of that, you can modify your scroll direction for a scroll wheel by holding shift.
When preventing the default behaviour, we should also include the other possible directions a user can scroll in. Luckily screens only have two dimensions, so adding deltaY to deltaX covers all cases in this scenario.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With