D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
pvernier
Full window
Github gist
Add circle at mouse's location (1/2)
Adds a circle at mouse's location every time the mouse moves
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> svg { background-color: #4d4d4d; width: 500px; height: 500px; } circle { fill: #b2182b; } </style> </head> <body> <svg></svg> </body> <script src="https://d3js.org/d3.v4.min.js"></script> <script type="text/javascript"> function mousemove() { var coords = d3.mouse(this); d3.select("svg").append("circle") .attr("cx", coords[0]) .attr("cy", coords[1]) .attr("r", 10) } var svg = d3.select("svg") svg.on("mousemove", mousemove) </script> </html>
https://d3js.org/d3.v4.min.js