block by steveharoz 184401755e8338fa8d7f619717dd4bc6

mouse delay canvas

Full Screen

Move the mouse smoothly from side to side to see a lag in the drawn position.

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//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>