[ Launch: tween dreams ] 5819559 by gelicia
-
-
Save gelicia/5819559 to your computer and use it in GitHub Desktop.
tween dreams
This file contains hidden or 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
{"description":"tween dreams","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
This file contains hidden or 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
//from http://stackoverflow.com/questions/13454993/increment-svg-text-with-transistion | |
var start_val = 1.34, | |
duration = 5000, | |
end_val = [2.54]; | |
var svg = d3.select("svg") | |
var text = svg | |
.append("text") | |
.text(start_val) | |
.attr("class", "txt") | |
.attr("x", 10) | |
.attr("y", function(d, i) { | |
return 50 + i * 30 | |
}) | |
.text(start_val) | |
text.transition() | |
.duration(1000) | |
.tween("text", function(d) { | |
var i = d3.interpolate(this.textContent, end_val[0]), | |
prec = (end_val[0] + "").split("."), | |
round = (prec.length > 1) ? Math.pow(10, prec[1].length) : 1; | |
return function(t) { | |
this.textContent = Math.round(i(t) * round) / round; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment