This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
02-ease.html
92 lines (75 loc) · 2.31 KB
/
02-ease.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="../scripts/d3/d3.min.js"></script>
<style type="text/css">
body {
padding: 1em;
}
text {
font-size: 1.5em;
}
button {
margin-bottom: 1em;
font-size: 1em;
}
</style>
</head>
<body>
<script>
var easing = [
"easeElastic",
"easeBounce",
"easeLinear",
"easeSin",
"easeQuad",
"easeCubic",
"easePoly",
"easeCircle",
"easeExp",
"easeBack"
];
var svg = d3.select("body")
.append("svg")
.attr("width", 960)
.attr("height", 500);
function circleTransition(easement, yPos) {
var timeCircle = svg.append("circle")
.attr("fill", "steelblue")
.attr("r", 20);
repeat();
function repeat() {
timeCircle
.attr('cx', 210) // position the circle at 40 on the x axis
.attr('cy', (yPos * 45) + 25) // position the circle at 250 on the y axis
.transition() // apply a transition
.ease(easement) // control the speed of the transition
.duration(4000) // apply it over 2000 milliseconds
.attr('cx', 720) // move the circle to 920 on the x axis
.transition() // apply a transition
.ease(easement) // control the speed of the transition
.duration(4000) // apply it over 2000 milliseconds
.attr('cx', 210) // return the circle to 40 on the x axis
.on("end", repeat); // when the transition finishes start again
};
var easeType = svg.append("text")
.attr("dy", ".35em") // set offset y position
.attr("x", 475)
.attr("text-anchor", "middle") // set anchor x justification
.attr("y", (yPos * 45) + 25)
.text(easing[yPos]);
};
circleTransition(d3.easeElastic, 0);
circleTransition(d3.easeBounce, 1);
circleTransition(d3.easeLinear, 2);
circleTransition(d3.easeSin, 3);
circleTransition(d3.easeQuad, 4);
circleTransition(d3.easeCubic, 5);
circleTransition(d3.easePoly, 6);
circleTransition(d3.easeCircle, 7);
circleTransition(d3.easeExp, 8);
circleTransition(d3.easeBack, 9);
</script>
</body>
</html>