• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HTML5 How do you prevent the page from scrolling when using the scroll-wheel ?

JasonTomLee

Member
Hello!
I wanted to know if it was possible to prevent the page from scrolling when I use the scroll wheel inside the HTML5 game. Thanks!
 

JasonTomLee

Member
It's for Itch.io, so they don't allow you to edit the Javascript unfortunately :( But i'll take a deeper look into the docs, thanks!
 

chmod777

Member
Code:
document.body.addEventListener("wheel", function(e) { e.preventDefault(); }, false);
I've only tested that on Firefox. If the game is on the top window, it will prevent the scrolling of the entire page. If the game is inside an iframe, the scrolling will only be prevented for the iframe.
 
Top