Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Example</title>
  6. <style>
  7. body {
  8. height: 3000px;
  9. }
  10. .dot {
  11. width: 2px;
  12. height: 2px;
  13. background-color: black;
  14. position: absolute;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <script>
  20. (function() {
  21. "use strict";
  22.  
  23. document.onmousemove = handleMouseMove;
  24. function handleMouseMove(event) {
  25. var dot, eventDoc, doc, body, pageX, pageY;
  26.  
  27. event = event || window.event; // IE-ism
  28.  
  29. // If pageX/Y aren't available and clientX/Y
  30. // are, calculate pageX/Y - logic taken from jQuery
  31. // Calculate pageX/Y if missing and clientX/Y available
  32. if (event.pageX == null && event.clientX != null) {
  33. eventDoc = (event.target && event.target.ownerDocument) || document;
  34. doc = eventDoc.documentElement;
  35. body = eventDoc.body;
  36.  
  37. event.pageX = event.clientX +
  38. (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
  39. (doc && doc.clientLeft || body && body.clientLeft || 0);
  40. event.pageY = event.clientY +
  41. (doc && doc.scrollTop || body && body.scrollTop || 0) -
  42. (doc && doc.clientTop || body && body.clientTop || 0 );
  43. }
  44.  
  45. // Add a dot to follow the cursor
  46. dot = document.createElement('div');
  47. dot.className = "dot";
  48. dot.style.left = event.pageX + "px";
  49. dot.style.top = event.pageY + "px";
  50. document.body.appendChild(dot);
  51. }
  52. })();
  53. </script>
  54.  
  55.  
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement