Reputation: 1619
I have a Website on which you cant scroll down, but I would like the user to be able to scroll to trigger an event. Any Ideas on how to do this?
Thanks in advance
Upvotes: 0
Views: 1626
Reputation: 1738
Listening to the wheel
event:
addEventListener("wheel", (e) => {
console.log("wheeling", e)
});
<div height="200vh"></div>
Upvotes: 0
Reputation: 724
You're looking for a wheel
event. mousewheel
events are deprecated. You want something like this, of course:
_addWheelListener = function( wheelEvent ) { // Warning
console.log(wheelEvent); // Does not work!
}
It's important to note that wheel
events seem to be treated very differently based on what browser and/or browser version your users are on. So you will want to be very careful about what you put inside the wheelListener
function.
Fortunately, someone at MZDN has done the heavy lifting for us
Once you copy paste their function into your javascript, you can define a wheelListener
as follows:
addWheelListener(document, function( wheelEvent ) {
console.log(wheelEvent);
});
Upvotes: 2