-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransition.html
56 lines (50 loc) · 1.57 KB
/
transition.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<doctype html>
<html>
<head>
<title>D3 example</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<script type="text/javascript">
var data = [10];
var canvas = d3.select("body")
.append("svg")
.attr('width', 500)
.attr('height', 500)
var circle = canvas.append('circle')
.attr('cx', 50)
.attr('cy', 100)
.attr('r', 25)
.attr('fill', '#000');
var circle2 = canvas.append('circle')
.attr('cx', 50)
.attr('cy', 200)
.attr('r', 25)
.attr('fill', 'green');
// var circles = canvas.selectAll("circle")
// .data(data)
// .style('fill', 'red')
// .exit()//.append('circle')
// // .attr('cx', 50)
// // .attr('cy', 50)
// // .attr('r', 25)
// .style('fill', 'green');
// Transition - animation for the circle
circle.transition()
.duration(3500)
.delay(1000)
.attr('cy', 300)
.each("start", function(){
d3.select(this).attr('fill', 'red');
}); // event listener
circle2.transition()
.duration(1500)
.delay(1000)
.attr('cy', 100)
.attr('cx', '200')
.each("start", function(){
d3.select(this).attr('fill', 'green');
}); // event listener
</script>
</body>
</html>