Overriding requestAnimationFrame and Date.now to force synchronous transitions.
Last active
February 9, 2016 01:57
-
-
Save mbostock/9644751 to your computer and use it in GitHub Desktop.
Immediate Transitions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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