Skip to content

Instantly share code, notes, and snippets.

@diafygi
Created November 15, 2011 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diafygi/1368775 to your computer and use it in GitHub Desktop.
Save diafygi/1368775 to your computer and use it in GitHub Desktop.
Make call after transition
<!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 circle
var chart = d3.select("#chart")
.append("svg:svg")
.attr("width", 200)
.attr("height", 200);
chart.append("svg:rect")
.attr("fill","steelblue")
.attr("x", 0)
.attr("y", 0)
.attr("width", 200)
.attr("height", 200);
//post response
function response(){
$("#response").text("This text should appear only after the color changes.");
}
//add trigger event
$("#trigger").click(function(e){
e.preventDefault();
//change color and fire response
chart.select("rect")
.transition()
.duration(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