-
-
Save wimdows/1370031 to your computer and use it in GitHub Desktop.
Make call after transition
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> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script> | |
<title>Delayed Call</title> | |
</head> | |
<body> | |
<div id="chart"></div> | |
<div id="trigger"><a href="#">Click to change the shape red.</a></div> | |
<div id="response"></div> | |
<script type="text/javascript"> | |
//create rectangle | |
var data = [20, 30, 40, 50]; | |
var chart = d3.select("#chart") | |
.append("svg:svg") | |
.attr("width", 300) | |
.attr("height", 200) | |
bars = chart.selectAll("g.bar") | |
.data(data) | |
.enter().append("svg:g") | |
.attr("class", "bar") | |
bars.append("svg:rect") | |
.attr("fill","steelblue") | |
.attr("x", function(d, i) { return 50+i*30; }) | |
.attr("y", 0) | |
.attr("height", function(d) { return d; }) | |
.attr("width", 30) | |
// .attr("height", 200); | |
//post response | |
function response(){ | |
$("#response").text("This text should appear after the (first) color changes."); | |
} | |
//add trigger event | |
$("#trigger").click(function(e){ | |
e.preventDefault(); | |
//change color and fire response | |
d3.selectAll("rect") //chart.select("rect") | |
.transition() | |
.duration(function(d,i) { return i*500; }) //1000 | |
.attr("fill", "red") | |
.each("end", response); | |
}); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment