Currently, I am working on a website that has horizontal overflow instead of the common vertical scroll. While everything seems to be functioning properly, I need to enhance the user experience by adjusting the amount scrolled to move larger sections of the screen at a time. However, the issue I am facing is that the code I am using does not provide a smooth transition; the movement appears quite clumsy.
The following is the code snippet I am utilizing, which runs during the mousewheel
event:
function scrollHorizontally(e) {
e = window.event || e;
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
document.documentElement.scrollLeft -= (delta*60); // Multiplied by 60
document.body.scrollLeft -= (delta*60); // Multiplied by 60
e.preventDefault();
}
As you can observe, I must adjust the delta * 60 to scroll an adequate amount.
I am interested in finding out if it is feasible to create a seamless transition rather than abruptly moving the user across a fixed pixel amount each time.
I have attempted using
scrollBy({ left: <amount>, behavior: 'smooth' });
, but it does not seem to offer a satisfactory user experience as it slightly eases the movement and feels laggy and inconsistent.
My goal is for the user to smoothly animate to the desired amount. Does anyone know if this is achievable?
This feature is implemented within a Vue 3 application, so I would appreciate any insights on how Vue handles this. Nonetheless, I am open to using vanilla JavaScript as well.
Thank you