Skip to content

Instantly share code, notes, and snippets.

@bycoffe
Created November 27, 2012 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bycoffe/4156859 to your computer and use it in GitHub Desktop.
Save bycoffe/4156859 to your computer and use it in GitHub Desktop.
Number easing with d3
<!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