JavaScript Replace vertical scroll by horizontal scroll vanilla javascript

I want to disable and replace the vertical scroll with horizontal one in Vanilla JavaScript. I am blocked when I try to replace my scroll values. I trust there is a simple simple (really simple) solution to that !

/* We define our function ???? */
function replaceVerticalScrollByHorizontal() {
  let scrollX = window.scrollX; /* Horizontal ➡️ */
  let scrollY = window.scrollY; /* Vertical ⬇️ */
  console.log({scrollX, scrollY});

  if (scrollY !== 0) {
    /* If there is a changement in verticalScroll ???? ⬇️ */
    const tempScrollY = scrollY; /* We create a temporary var to stock our scrollY value */
    scrollX = scrollY; /* Horizontal = Vertical */
    scrollY = 0; /* We reset the vertical because we don't want any vertical scroll */
    window.scrollTo(scrollX, scrollY); /* We scroll to our value */
    scrollY = tempScrollY; /* We replace the value of our vertical var with the temporary one */
  }
  /* If no verticalScroll changement, exit of this function ???? ⬇️ */
  return;
}

/* Listener on window once we start scrolling, we run our function ???? */
window.addEventListener('scroll', replaceVerticalScrollByHorizontal);

There is a little jsfiddle with my problem: https://jsfiddle.net/zynj64m7/2/

Answer:1

I'm using https://www.npmjs.com/package/mqtt with React. In my component I have: componentDidMount:function(){ client.subscribe('test/topic'); client.on('message',function(topic,...

I'm using https://www.npmjs.com/package/mqtt with React. In my component I have: componentDidMount:function(){ client.subscribe('test/topic'); client.on('message',function(topic,...

  1. react mqtt subscribe

In JavaScript, I am running a forEch method on an array of objects. Would like to run through my JSON and replace a substring in a string with a new string if the condition is met. The issue is this:...

In JavaScript, I am running a forEch method on an array of objects. Would like to run through my JSON and replace a substring in a string with a new string if the condition is met. The issue is this:...

I have a string like this : var name="C:\Users\Desktop\task.txt"; I want to get the last index of backslash in the above string. How to do it ?

I have a string like this : var name="C:\Users\Desktop\task.txt"; I want to get the last index of backslash in the above string. How to do it ?

I am using the Bubbles plugin with the Flot charting library for JQuery. The data I have is dynamic and can be quite varied within the X, Y, and Z values. The main issue I am having is the size of the ...

I am using the Bubbles plugin with the Flot charting library for JQuery. The data I have is dynamic and can be quite varied within the X, Y, and Z values. The main issue I am having is the size of the ...

  1. flow bubbles plugin - bubble size