Created
May 1, 2017 15:31
-
-
Save tuffacton/1cc0f4170e3ca67f9959443c20f3b104 to your computer and use it in GitHub Desktop.
Example // source http://jsbin.com/nabihac
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Example</title> | |
<style> | |
body { | |
height: 3000px; | |
} | |
.dot { | |
width: 2px; | |
height: 2px; | |
background-color: black; | |
position: absolute; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
(function() { | |
"use strict"; | |
document.onmousemove = handleMouseMove; | |
function handleMouseMove(event) { | |
var dot, eventDoc, doc, body, pageX, pageY; | |
event = event || window.event; // IE-ism | |
// If pageX/Y aren't available and clientX/Y | |
// are, calculate pageX/Y - logic taken from jQuery | |
// Calculate pageX/Y if missing and clientX/Y available | |
if (event.pageX == null && event.clientX != null) { | |
eventDoc = (event.target && event.target.ownerDocument) || document; | |
doc = eventDoc.documentElement; | |
body = eventDoc.body; | |
event.pageX = event.clientX + | |
(doc && doc.scrollLeft || body && body.scrollLeft || 0) - | |
(doc && doc.clientLeft || body && body.clientLeft || 0); | |
event.pageY = event.clientY + | |
(doc && doc.scrollTop || body && body.scrollTop || 0) - | |
(doc && doc.clientTop || body && body.clientTop || 0 ); | |
} | |
// Add a dot to follow the cursor | |
dot = document.createElement('div'); | |
dot.className = "dot"; | |
dot.style.left = event.pageX + "px"; | |
dot.style.top = event.pageY + "px"; | |
document.body.appendChild(dot); | |
console.log([event.pageX,event.pageY]) | |
} | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Attempt to add timer