I have some simple code that returns whether I'm scrolling up or down. I want to use it as a function with return, like this:
var scripts = {
getScrollDirection: function() {
var dir;
$(document).on('mousewheel DOMMouseScroll', function(e) {
if(e.originalEvent.wheelDelta / 120 > 0) {
dir = 'up';
} else {
dir = 'down';
}
});
return dir;
}
}
When I call scripts.getScrollDirection, I get undefined. What I am doing wrong?
dirwill stay undefined. Maybe you want to place the code for the function inmousewheel DOMMouseScroll?console.loginside theif/elsestatements, it works. I really want to avoid placing function insidemousewheelevent.dir. Outside the callback, and before it is called, you have not.