Skip to content

Commit 46e3ef9

Browse files
committed
better transitions
1 parent 079a1ba commit 46e3ef9

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

transition.mjs

+23-10
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ export function fly(node, {
1818
duration = 400,
1919
easing = cubicOut,
2020
x = 0,
21-
y = 0
21+
y = 0,
22+
opacity = 0
2223
}) {
2324
const style = getComputedStyle(node);
24-
const opacity = +style.opacity;
25+
const target_opacity = +style.opacity;
2526
const transform = style.transform === 'none' ? '' : style.transform;
2627

28+
const od = target_opacity - opacity;
29+
2730
return {
2831
delay,
2932
duration,
3033
easing,
3134
css: t => `
3235
transform: ${transform} translate(${(1 - t) * x}px, ${(1 - t) * y}px);
33-
opacity: ${t * opacity}`
36+
opacity: ${1 - (od * u)}`
3437
};
3538
}
3639

@@ -73,13 +76,12 @@ export function scale(node, {
7376
start = 0,
7477
opacity = 0
7578
}) {
76-
const sd = 1 - start;
77-
const od = 1 - opacity;
79+
const style = getComputedStyle(node);
80+
const target_opacity = +style.opacity;
81+
const transform = style.transform === 'none' ? '' : style.transform;
7882

79-
const transform = (
80-
node.style.transform ||
81-
getComputedStyle(node).transform
82-
).replace('none', '');
83+
const sd = 1 - start;
84+
const od = target_opacity - opacity;
8385

8486
return {
8587
delay,
@@ -94,11 +96,22 @@ export function scale(node, {
9496

9597
export function draw(node, {
9698
delay = 0,
97-
duration = 800,
99+
speed,
100+
duration,
98101
easing = cubicInOut
99102
}) {
100103
const len = node.getTotalLength();
101104

105+
if (duration === undefined) {
106+
if (speed === undefined) {
107+
duration = 800;
108+
} else {
109+
duration = len / speed;
110+
}
111+
} else if (typeof duration === 'function') {
112+
duration = duration(len);
113+
}
114+
102115
return {
103116
delay,
104117
duration,

0 commit comments

Comments
 (0)