daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. detect mouse direction
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <div style="width: 500px; height: 500px; background: red;">
  7.     </div>
  8.  
  9. </body>
  10.  
  11.  
  12. var mY = 0;
  13. $('body').mousemove(function(e) {
  14.     mY = e.pageY;
  15.     if (e.pageY < mY) {
  16.         console.log('From Bottom');
  17.         return;
  18.  
  19.     } else {
  20.         console.log('From Top');
  21.     }
  22.  
  23. });
  24.    
  25. var mY = 0;
  26. $('body').mousemove(function(e) {
  27.  
  28.     // moving upward
  29.     if (e.pageY < mY) {
  30.         console.log('From Bottom');
  31.  
  32.     // moving downward
  33.     } else {
  34.         console.log('From Top');
  35.     }
  36.  
  37.     // set new mY after doing test above
  38.     mY = e.pageY;
  39.  
  40. });
  41.    
  42. var mY = 0;
  43. $('body').mousemove(function(e) {
  44.  
  45.     if (e.pageY < mY) {
  46.         console.log('From Bottom');
  47.  
  48.     } else {
  49.         console.log('From Top');
  50.     }
  51.     mY = e.pageY;
  52.  
  53. });
  54.    
  55. //Values starts at middle of page
  56. var mY = $('window').height()/2;
  57.  
  58. //Compares position to mY and Outputs result to console
  59. $('body').mousemove(function(e) {
  60.     if (e.pageY < mY) {
  61.         console.log('Going Up');  
  62.     }
  63.     else {
  64.         console.log('Going Down');
  65.     }
  66.     mY = e.pageY;
  67. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top