-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch.js
120 lines (96 loc) · 2.83 KB
/
scratch.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function relative_add(x) {
return "+=" + x;
}
var duration = 4000;
var box_start = 400;
var box_distance = 200;
var event_width = 25;
function closest_to_box() {
result = [];
$(".filtering > .events > .event").each(function() {
value = parseFloat($(this).attr("x"));
result.push(value);
});
return box_start - Math.max.apply(Math, result) - event_width;
}
function furthest_from_box() {
result = [];
$(".filtering > .events > .event").each(function() {
value = parseFloat($(this).attr("x"));
result.push(value);
});
return box_start - Math.min.apply(Math, result) - event_width;
}
var closest_d = closest_to_box();
var furthest_d = furthest_from_box();
function build_keep_animation(selector) {
start = box_start - (parseFloat($(selector).attr("x")) + event_width);
end = (furthest_d - start) + closest_d;
total_distance = start + end + box_distance;
return {
targets: selector,
easing: "linear",
keyframes: [
{
duration: ((start / total_distance) * duration),
translateX: start
},
{
duration: ((box_distance / total_distance) * duration),
translateX: relative_add(box_distance)
},
{
duration: ((end / total_distance) * duration),
translateX: relative_add(end)
}
]
};
}
function build_discard_animation(selector) {
start = box_start - (parseFloat($(selector).attr("x")) + event_width);
return {
targets: selector,
easing: "linear",
keyframes: [
{
duration: ((start / 650) * duration),
translateX: start
},
{
duration: 700,
translateX: relative_add((box_distance / 2) + (event_width / 2))
},
{
duration: 700,
translateY: 120,
opacity: [1, 0]
}
]
};
}
function build_animation(selector) {
if ($(selector).hasClass("keep")) {
return build_keep_animation(selector);
} else {
return build_discard_animation(selector);
}
}
var controlsProgressEl = $(".controls > .progress");
var timeline = anime.timeline({
loop: true,
update: function(anim) {
controlsProgressEl.val(timeline.progress);
}
});
timeline.add(build_animation(".filtering > .events > .event.e-1"));
timeline.add(build_animation(".filtering > .events > .event.e-2"), 1000);
timeline.add(build_animation(".filtering > .events > .event.e-3"), 2000);
timeline.add(build_animation(".filtering > .events > .event.e-4"), 3000);
timeline.add(build_animation(".filtering > .events > .event.e-5"), 4000);
timeline.add(build_animation(".filtering > .events > .event.e-6"), 5000);
$(".controls > .play").click(timeline.play);
$(".controls > .pause").click(timeline.pause);
$(".controls > .restart").click(timeline.restart);
controlsProgressEl.on('input', function() {
timeline.seek(timeline.duration * (controlsProgressEl.val() / 100));
});