Guest User

Untitled

a guest
Jan 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. if (!e) var e = window.event; // Internet Explorer
  2.  
  3. if (!e) e = window.event; // Internet Explorer
  4.  
  5. <html>
  6. <head>
  7. <title>Mouse Coordinates</title>
  8. <script type="text/javascript">
  9. function getCoords(e) {
  10. var x = 0; // x and y positions
  11. var y = 0;
  12. if (!e) var e = window.event; // Internet Explorer
  13. if (e.pageX || e.pageY) { // Firefox
  14. x = e.pageX;
  15. y = e.pageY;
  16. }
  17. else if (e.clientX || e.clientY) {
  18. x = e.clientX + document.body.scrollLeft
  19. + document.documentElement.scrollLeft;
  20. y = e.clientY + document.body.scrollTop
  21. + document.documentElement.scrollTop;
  22. }
  23. // x and y contain the mouse position
  24. // relative to the document
  25. alert(x + ", " + y);
  26. }
  27. </script>
  28. </head>
  29. <body>
  30. <div style="background-color: aqua; position: absolute; top: 50px"
  31. onmouseover="return getCoords(event);">
  32. <h1>Mouse positions are relative to the document, not the
  33. <div> container</h1>
  34. </div>
  35. </body>
  36. </html>
  37.  
  38. function getCoords(e) {
  39. e = e || window.event;
  40. ...
  41. }
  42.  
  43. x = 12; // using the variable "before" it is declared works
  44. var x = x + 1;
Add Comment
Please, Sign In to add comment