-
Notifications
You must be signed in to change notification settings - Fork 0
/
transition.html
51 lines (50 loc) · 1.17 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
div {
position: absolute;
}
</style>
</head>
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var data = ['cat', 'dog', 'cat', 'dog', 'cat', 'dog'],
duration = 1500;
d3.select('body').selectAll('div')
.data(data)
.enter()
.append('div')
.style('width', '30px')
.style('height', '30px')
.style('background-color', 'blue')
.style('top', function(d,i){
return i*40 + 'px';
})
.style('color', '#fff')
.text(function(d,i){
return i;
})
.transition()
.duration(duration)
.delay(1000)
.style('left', '100px')
.on('start', function(){
d3.select(this).text('start')
})
.filter(function(d){
return d == 'dog';
})
.transition()
.duration(duration)
.delay(1000)
.on('start', function(){
d3.select(this).text('second')
})
.style('left', '500px')
</script>
</body>
</html>