D
D
Denis Bukreev2016-09-23 13:53:51
JavaScript
Denis Bukreev, 2016-09-23 13:53:51

Is there a simple way to remap the mouse wheel to vertical scroll?

So it goes.
I thought for a long time, googled for a long time.
Decided to ask just in case.
If not, what is the best way to implement it?
PS: without jQuery and other bells and whistles - native JS according to ES6

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2016-09-23
@denisbookreev

document.onwheel = function(e){
   e.preventDefault();

   //Дельту желательно немного приумножать
   window.scrollBy(e.deltaY, 0); //С вертикального на горизонтальный
   window.scrollBy(0, e.deltaX); //С горизонтального на вертикальный
}

D
Denis Bukreev, 2016-09-23
@denisbookreev

In my case, the scroll occurs not in the window, but in the c block. id="timeline"
For this case, the code is as follows:

window.timeline.onwheel = e => {
  e.preventDefault();
  timeline.scrollLeft = timeline.scrollLeft + e.deltaY;
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question