Looking for a way to trigger a function or loop when scrolling up or down using the onwheel event. Check out the code snippet below:
let demo = document.querySelector('#demo');
let c = 0;
window.onwheel = function() {
c ++;
demo.innerHTML = c;
}
body{
height: 300vh;
}
h1{
position: fixed;
text-align: center;
width: 100vw;
}
<h1 id="demo" > Hello World </h1>
Currently, the number increments when scrolling up, but I need it to decrement when scrolling down. Looking for a clear JavaScript solution. Thank you.