I'm pretty new to front-end javascript (in particular DOM manipulation and JQuery), I wanted to achieve an effect where if a user scroll the mouse wheel the image on the page changes, I then found that the best way to this is a wheel event (I got that from this question). I implemented it but nothing happens when I scroll, even alerts aren't working.
I would really appreciate any help, and even additional information if deemed necessary by the author of the answer. Thanks in advance.
Here's what I've done so far:
<!DOCTYPE html>
<html>
<head>
<title>NERD</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<div id="Banner">
<img id="Bimage" src="./images/Avatar.png" alt="Logo">
</div>
<script>
var pages = ["./images/IMAGE1.png", "./images/IMAGE2.png", "./images/IMAGE3.png"],
position = 0;
document.getElementById("image").on('wheel', mouseHandler);
function mouseHandler() {
return function(e) {
if(e.originalEvent.deltaY < 0) {
position -= 1;
this.attr("src", pages[position]);
} else {
position += 1;
this.attr("src", pages[position]);
}
}
}
</script>
</body>
</html>
The error message from the console says: Cannot read property 'on' of null at index.html:71