Created
November 27, 2012 20:40
-
-
Save bycoffe/4156859 to your computer and use it in GitHub Desktop.
Number easing with d3
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> | |
<html> | |
<head> | |
<style type="text/css"> | |
h1 { | |
margin-left: 20px; | |
margin-top: 20px; | |
font-family: Helvetica, Arial, sans-serif; | |
font-size: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1 id="num">0</h1> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.5.0"></script> | |
<script type="text/javascript"> | |
(function() { | |
d3.select('#num') | |
.transition() | |
.duration(3500) | |
.ease('cubic-out') | |
.tween('text', function() { | |
var i = d3.interpolate(this.textContent, "100"); | |
return function(t) { | |
this.textContent = Math.round(i(t)); | |
}; | |
}); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment