Skip to content

Instantly share code, notes, and snippets.

@steveharoz
Last active March 6, 2017 18:20
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 steveharoz/84150ed4a12203d0ba8e5ad18881c559 to your computer and use it in GitHub Desktop.
Save steveharoz/84150ed4a12203d0ba8e5ad18881c559 to your computer and use it in GitHub Desktop.
mouse delay

Move the mouse smoothly from side to side to see a lag in the circle's position.

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<svg></svg>
<script src="http://d3js.org/d3.v4.min.js"></script>
<script>
var width = 960,
height = 500;
var mouseLocation = [0,0];
var svg = d3.select("body").select("svg")
.attr("width", width)
.attr("height", height);
var cursor = svg.append('circle')
.attr("r", 2)
.attr("fill", 'darkblue');
// update mouse location
d3.select(window).on("mousemove", () => { mouseLocation = d3.mouse(svg.node()); });
// show mouse
d3.timer(function() {
cursor.attr("transform", 'translate(' + mouseLocation + ')');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment