Skip to content

Instantly share code, notes, and snippets.

Last active February 6, 2018 12:07
What would you like to do?
d3.js Loading Spinner Icon
<html lang="en">
<div id="loader_container"></div>
<script src=""></script>
function loader(config) {
return function() {
var radius = Math.min(config.width, config.height) / 2;
var tau = 2 * Math.PI;
var arc = d3.svg.arc()
var svg ="svg")
.attr("width", config.width)
.attr("height", config.height)
.attr("transform", "translate(" + config.width / 2 + "," + config.height / 2 + ")")
var background = svg.append("path")
.datum({endAngle: 0.33*tau})
.style("fill", "#4D4D4D")
.attr("d", arc)
.call(spin, 1500)
function spin(selection, duration) {
.attrTween("transform", function() {
return d3.interpolateString("rotate(0)", "rotate(360)");
setTimeout(function() { spin(selection, duration); }, duration);
function transitionFunction(path) {
.attrTween("stroke-dasharray", tweenDash)
.each("end", function() {; });
var myLoader = loader({width: 960, height: 500, container: "#loader_container", id: "loader"});
Copy link

nikicc commented Apr 2, 2014


I have a problem using this in Safari during the reloading of a new web page. The main idea is that this spinner should spin while the new page is loading. Although this works just fine in Firefox, Chrome and Explorer, this does not work in Safari. I also posted this question to StackOverflow (

Do you have any ideas how to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment