javascript - Mapping arrow keys to scrollwheel function? -
i running slideshow on client site. slideshow animates each slide, , relies solely on scrollwheel of mouse although 'swipes' when in touchscreen devices.
it's important note here page doesn't actually scoll when using scrollwheel, activates next slide animation. webpage never scolls in traditional sense...
however people don't use scrollwheel, use keyboard arrows.
is there way, ideally using javascript, force arrow keys emulate single scroll of mousewheel?
i apologise lack of code or previous efforts - haven't been able find regards problem , code embedded in slideshow extension. i'm hoping add own js complement base slideshow.
you try trigger mousewheel event on gallery element code using this:
var element = <reference element mousewheel events bound to> document.addeventlistener('keydown', function(e){ var event = new event('mouseevents'); event.initevent('mousewheel', true, true); switch(e.keycode){ case '37': event.wheeldelta = -1; element.dispatchevent(event); break; case '39': event.wheeldelta = 1; element.dispatchevent(event); break; } });
https://developer.mozilla.org/en-us/docs/web/guide/events/creating_and_triggering_events
Comments
Post a Comment