if you use if / else, it will always output "Going Down", although e.pageY == mY.
Use 2 if-statements instead!
var mY = 0; $('body').mousemove(function(e) { // moving upward if (e.pageY < mY) { console.log('From Bottom'); // moving downward } if (e.pageY > mY) { console.log('From Top'); } // set new mY after doing test above mY = e.pageY; });
just copied the code from macek and replaced 'else' with 'if (...)' btw
source share