Created
April 25, 2013 17:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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