Skip to content

Instantly share code, notes, and snippets.

@nikcorg
Created November 2, 2012 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikcorg/4001207 to your computer and use it in GitHub Desktop.
Save nikcorg/4001207 to your computer and use it in GitHub Desktop.
Anonymous state retaining event listener
document.addEventListener(
"mousemove",
function (e) {
var sample = {x: parseInt(e.clientX, 10) || 0, y: parseInt(e.clientY, 10) || 0};
var diff = {x: sample.x - this.lastSample.x, y: sample.y - this.lastSample.y};
this.lastSample = sample;
console.dir(diff);
}.bind({lastSample: {x: 0, y: 0}}),
false
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment