Move the mouse smoothly from side to side to see a lag in the drawn position.
Last active
March 6, 2017 15:30
-
-
Save steveharoz/184401755e8338fa8d7f619717dd4bc6 to your computer and use it in GitHub Desktop.
mouse delay canvas
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> | |
<meta charset="utf-8"> | |
<body> | |
<script src="http://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var width = 960, | |
height = 300; | |
var canvas = d3.select("body").append("canvas") | |
.attr("width", width) | |
.attr("height", height); | |
var context = canvas.node().getContext("2d"); | |
context.fillStyle = 'steelblue'; | |
var mouseLocation = [0,0]; | |
d3.select(window).on("mousemove", () => { | |
mouseLocation[0] = d3.event.clientX; | |
mouseLocation[1] = d3.event.clientY; | |
}); | |
// show mouse | |
d3.timer(function() { | |
context.clearRect(0, 0, width, height); | |
context.beginPath(); | |
context.arc(mouseLocation[0], mouseLocation[1], 2, 0, 2 * Math.PI); | |
context.fill(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment