Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 9, 2016 01:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbostock/9644751 to your computer and use it in GitHub Desktop.
Save mbostock/9644751 to your computer and use it in GitHub Desktop.
Immediate Transitions
license: gpl-3.0

Overriding requestAnimationFrame and Date.now to force synchronous transitions.

<!DOCTYPE html>
<meta charset="utf-8">
<script>
var callbacks = [];
requestAnimationFrame = function(callback) {
callbacks.push(callback);
};
flushAnimationFrames = function() {
var now = Date.now;
Date.now = function() { return Infinity; };
callbacks.forEach(function(callback) { try { callback(); } catch (e) { console.error(e); } });
callbacks = [];
Date.now = now;
};
</script>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
d3.select("body").transition()
.duration(5000)
.style("background", "red");
flushAnimationFrames();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment