Created
November 15, 2011 23:44
-
-
Save diafygi/1368775 to your computer and use it in GitHub Desktop.
Make call after transition
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
<!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