D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jfourmond
Full window
Github gist
Loading Circle V0 - Movement
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> const width = 960; const height = 500; const midWidth = Math.floor(width/2); const midHeight = Math.floor(height/2); const color = d3.scaleOrdinal(d3.schemeCategory10); let colorVar = 0; function rotateClockwise(transition) { transition .duration(5000) .ease(d3.easeLinear) .attrTween("cx", function() { let that = d3.select(this); return function(t) { return(midWidth + 50 * Math.cos(2 * Math.PI * t)); } }) .attrTween("cy", function() { let that = d3.select(this); return function(t) { return(midHeight + 50 * Math.sin(2 * Math.PI * t)); } }).on("end", function() { d3.select(this).transition().call(rotateClockwise); });; } const svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height); const circle = svg.append("circle") .attr("cx", midWidth) .attr("cy", midHeight) .attr("r", 20) .attr("fill", color(colorVar++)); circle.transition().call(rotateClockwise); </script> </body>
https://d3js.org/d3.v4.min.js