-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.js
66 lines (56 loc) · 1.72 KB
/
animate.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
export async function moveHalfway(element, config) {
await waitForRunner(element.animate(750, 100, 'now')
.ease('>')
.attr({
x: config.halfwayPosition,
opacity: 0.5
})
);
}
export async function moveToEnd(element, config, moveY) {
await waitForRunner(element.animate(500, 250, 'now')
.ease('<')
.attr({
x: config.endPosition,
y: moveY ? moveY : 0
}));
}
export function updateElementText(element, newValue) {
transformTextNode(element.children()[1], String(newValue));
}
export function updateElementIndex(element, newIndex) {
transformTextNode(element.children()[2], String(newIndex));
}
export function updateElementColor(element, newColor) {
let container = element.children()[0];
container.fill(newColor);
}
export function convertArrayElementToValue(element) {
element.children()[3].remove();
element.children()[2].remove();
let currentHeight = element.children()[0].attr('height');
element.children()[0].animate(500, 250, 'now').attr({
height: currentHeight * 0.65
});
}
export function convertArrayIndexToValue(element) {
element.children()[3].remove();
element.children()[1].remove();
let rect = element.children()[0];
let currentHeight = rect.attr('height');
let currentY = rect.attr('y');
rect.animate(500, 250, 'now').attr({
height: currentHeight * 0.35,
y: currentY + (currentHeight * 0.65)
});
}
function transformTextNode(node, newValue) {
node.children()[0].text(newValue);
}
async function waitForRunner(runner) {
return new Promise(function(resolve) {
runner.after(() => {
resolve();
});
});
}