Skip to content

Instantly share code, notes, and snippets.

@tuffacton
Created May 2, 2017 03:15
Show Gist options
  • Save tuffacton/a360a7cbb77de16a8ead43c0d59106bb to your computer and use it in GitHub Desktop.
Save tuffacton/a360a7cbb77de16a8ead43c0d59106bb to your computer and use it in GitHub Desktop.
Example // source http://jsbin.com/sufagu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<style>
body {
/* Uncomment below and set image URL to a background of choice*/
/*background-image: url('https://s-media-cache-ak0.pinimg.com/originals/ef/6f/66/ef6f66567e8e6f077598df1094f1df70.jpg'); */
height: 3000px;
}
.dot {
width: 2px;
height: 2px;
background-color: black;
position: absolute;
}
</style>
</head>
<body>
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<script>
(function() {
"use strict";
document.onmousemove = handleMouseMove;
function handleMouseMove(event) {
var dot, eventDoc, doc, body, pageX, pageY;
event = event || window.event;
// Find the position of the mouse cursor at a given time.
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 );
}
// Create dots following the mouse cursor
// Velocity can be derived from space between dots
// as they are created during equivalent time
// intervals of movement
dot = document.createElement('div');
dot.className = "dot";
// Create dot element x-axis location
dot.style.left = event.pageX + "px";
// Create dot element y-axis location
dot.style.top = event.pageY + "px";
// Add from "dot" class for one cursor event.
document.body.appendChild(dot);
// Finds the current time of movement
// Expressed in Unix Milliseconds (time since Epoch)
// Siginifcant time has been shaved off to reduce size of data
var currentTime = moment().valueOf() - 1493684400357;
var parseTime = currentTime
// Log the combined array of dot position and time
// [X, Y, time] for each dot as it comes
console.log([event.pageX,event.pageY, currentTime])
}
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment