0

I attach events from different browsers (versions) and last version of Firefox consists 3/3 of them, last version of Chrome constits 2/3 of them. So, how to process just one of events instead of 3/3 or 2/3?

$(window).on('wheel mousewheel DOMMouseScroll', (e) => {

    console.log(e);

});
dt_
  • 95
  • 1
  • 10
  • Possible duplicate of [Mousewheel event in modern browsers](https://stackoverflow.com/questions/14926366/mousewheel-event-in-modern-browsers) – fen1x Dec 25 '18 at 07:10
  • No, it's not. Example in answer to that question isn't good at all, because Firefox fires events twice, because it has and mousewheel and DOMMouseScroll. – dt_ Dec 25 '18 at 07:15
  • Latest Firefox fires `DOMMouseScroll` and latest Chrome fires `mousewheel`, as you can check in [this codepen](https://codepen.io/fen1x/pen/oJwLvV?editors=1111) – fen1x Dec 25 '18 at 07:22
  • Yes, i know it. But if you test my code in Firefox you will get 3 logs in your console, in Chrome you will get 2 logs. I want to make that just one event will be chosen and fired. As i understand that i don't need to use new event wheel to just detect scroll and get from it direction? Are mousewheel and DOMMouseScroll enough? – dt_ Dec 25 '18 at 07:39
  • 1
    To make your example work in Chrome and Firefox - yes, you just need to remove `wheel`. But [MDN](https://developer.mozilla.org/en-US/docs/Web/Events/wheel) advices replacing every non-standart wheel event (like `DOMMouseScroll` and `mousewheel`) with `wheel` event. Check cross-browser example at the bottom of the MDN article. – fen1x Dec 25 '18 at 07:48

0 Answers0