Monday, 19 April 2021

Dispatch wheel event to simulate scrolling on a scrollable div

So what I have are two divs - div1 and div2. div2 is higher in z-order than div1. div2 is not scrollable while div1 is scrollable. I am capturing the "wheel" event on the div2 element and dispatching them onto div1. I expect div1 to scroll after dispatching the "wheel" event but nothing really happens.

div2.addEventListener("wheel", ev => {
     var new_event = new ev.constructor(ev.type, ev)
     div1.dispatchEvent(new_event);
});

I don't want to manually scroll the div1 by calling div1.scrollBy(...) methods. Any help would be appreciated.



from Dispatch wheel event to simulate scrolling on a scrollable div

No comments:

Post a Comment