Skip to content

Instantly share code, notes, and snippets.

@longlostnick
Created April 25, 2013 17:02
Show Gist options
  • Save longlostnick/5461340 to your computer and use it in GitHub Desktop.
Save longlostnick/5461340 to your computer and use it in GitHub Desktop.
Try to detect when someone's mouse is moving upward off the page
(function() {
var current_scroll = 0;
var last_mouse_y = null;
$(document)
.scroll(function() {
current_scroll = $(this).scrollTop();
})
.mousemove(function(e) {
var speed = last_mouse_y - e.pageY;
var success_val = e.pageY - speed;
if (success_val < last_mouse_y && success_val <= current_scroll) {
// yay!
}
last_mouse_y = e.pageY;
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment