var mY = 0;
$('body').mousemove(function(e) { // moving upward if (e.pageY < mY) { console.log('From Bottom'); // moving downward } else { console.log('From Top'); } // set new mY after doing test above mY = e.pageY;
});
This uses jquery. We select the whole body and add the move mouse function which detects the mouse. The first if statement moves up after comparing the page coordinates and vice versa for else. Then we save the y coordinates into the variable mY