-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathindex.ts
More file actions
51 lines (46 loc) · 1.23 KB
/
index.ts
File metadata and controls
51 lines (46 loc) · 1.23 KB
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
import type { EasingFunction, TransitionConfig } from "svelte/transition";
import { linear } from "svelte/easing";
type Direction =
| "top"
| "top-right"
| "right"
| "bottom-right"
| "bottom"
| "bottom-left"
| "left"
| "top-left";
interface SlideParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
direction?: Direction;
}
function getTransform(direction: Direction, value: number) {
switch (direction) {
case "top":
return `translateY(-${value}%)`;
case "bottom":
return `translateY(${value}%)`;
case "left":
return `translateX(-${value}%)`;
case "right":
return `translateX(${value}%)`;
case "top-left":
return `translateY(-${value}%) translateX(-${value}%)`;
case "top-right":
return `translateY(-${value}%) translateX(${value}%)`;
case "bottom-left":
return `translateY(${value}%) translateX(-${value}%)`;
case "bottom-right":
return `translateY(${value}%) translateX(${value}%)`;
}
}
export function slide(node: HTMLElement, params: SlideParams = {}): TransitionConfig {
const { delay = 0, duration = 300, easing = linear, direction = "top" } = params;
return {
delay,
duration,
easing,
css: (t, u) => `transform: ${getTransform(direction, u * 100)}; opacity: ${t}`,
};
}