Im making a plugin with jquery and it makes use of a mouse scroll event. The problem is i get it scrolls down even when im scrolling up.
Here i got my code
HTML:
<body>
<!-- <div id="element"></div> -->
<div id='wrapper'>
<img id='img1' src='./images/image1.jpg'>
</div>
<script>
$(document).ready(function()
{
$(document).scrollPage();
});
</script>
</body>
Javascript:
$.extend(Plugin.prototype, {
init: function () {
document.addEventListener('scroll', this.checkScroll);
},
checkScroll: function(event) {
//Guess the delta.
var delta = 0;
if (event.wheelDelta) {
delta = event.wheelDelta/120;
}
else if (event.detail) {
delta = -event.detail/3;
}
if(delta / 120 > 0){
console.log('up');
}
else{
console.log('down');
}
}
});
Somehow when i scroll the code always come in the else statement console.log('down');
is the formula delta / 120 > 0 wrong in this code?