I have a web app where with an immersive view. In this view, i can zoom in or zoom out with the mouse wheel action.
What i would like to do is to create 2 buttons which call javascript function and simulate the mouse wheel actions. I tried with :
window.scrollTo(0,300);
but scrolling in my case doesn't zoom (seems like only mouse wheel action work).
Do you have any idea, how can i simulate the mouse wheel up or down within the javascript ?
thank you
About Mousewheel JS Mousewheel is a jQuery plugin that adds cross-browser mouse wheel support. Also, Scroll distance can be measured using Delta normalization.
The wheel event fires when the user rotates a wheel button on a pointing device (typically a mouse). This event replaces the non-standard deprecated mousewheel event.
So i solve my problem after some research.
Here is what i did :
I create a mouse event and pass it wheel event.
var evt = document.createEvent('MouseEvents');
evt.initEvent('wheel', true, true);
Then i can set deltaY depending on if you want a wheel up or a wheel down.
evt.deltaY = +120;
// evt.deltaY = -120
And you can pass this event to your element by doing so :
element.dispatchEvent(evt);
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