-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathtimeline.ts
More file actions
29 lines (22 loc) · 897 Bytes
/
timeline.ts
File metadata and controls
29 lines (22 loc) · 897 Bytes
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
import * as core from '@diffusionstudio/core';
export function setupTimeline(composition: core.Composition) {
composition.on('playback:time', () => {
const pos = composition.currentTime / composition.duration;
cursor.style.left = `${timeline.clientWidth * pos}px`;
});
let seeking = false;
timeline.addEventListener('mousemove', async (evt: MouseEvent) => {
const pos = evt.offsetX / timeline.clientWidth;
if(!seeking) {
seeking = true;
await composition.seek(composition.duration * pos);
seeking = false;
}
});
timeline.addEventListener('click', (evt: MouseEvent) => {
const pos = evt.offsetX / timeline.clientWidth;
composition.seek(composition.duration * pos);
});
}
const timeline = document.querySelector('[id="timeline"]') as HTMLDivElement;
const cursor = document.querySelector('[id="timeline"] > div') as HTMLDivElement;