File tree Expand file tree Collapse file tree 3 files changed +25
-17
lines changed
runtime-runes/samples/transition-delayed Expand file tree Collapse file tree 3 files changed +25
-17
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ class Animation {
35
35
#target;
36
36
#keyframes;
37
37
#duration;
38
+ #delay;
38
39
39
40
#offset = raf . time ;
40
41
@@ -47,12 +48,13 @@ class Animation {
47
48
/**
48
49
* @param {HTMLElement } target
49
50
* @param {Keyframe[] } keyframes
50
- * @param {{ duration: number } } options // TODO add delay
51
+ * @param {{ duration: number, delay: number } } options
51
52
*/
52
- constructor ( target , keyframes , { duration } ) {
53
+ constructor ( target , keyframes , { duration, delay } ) {
53
54
this . #target = target ;
54
55
this . #keyframes = keyframes ;
55
56
this . #duration = duration ;
57
+ this . #delay = delay ?? 0 ;
56
58
57
59
// Promise-like semantics, but call callbacks immediately on raf.tick
58
60
this . finished = {
@@ -73,7 +75,9 @@ class Animation {
73
75
}
74
76
75
77
_update ( ) {
76
- this . currentTime = raf . time - this . #offset;
78
+ this . currentTime = raf . time - this . #offset - this . #delay;
79
+ if ( this . currentTime < 0 ) return ;
80
+
77
81
const target_frame = this . currentTime / this . #duration;
78
82
this . #apply_keyframe( target_frame ) ;
79
83
Original file line number Diff line number Diff line change @@ -30,20 +30,19 @@ export default test({
30
30
'<button>toggle</button><p style="opacity: 0.5;">delayed fade</p>'
31
31
) ;
32
32
33
- raf . tick ( 201 ) ;
33
+ raf . tick ( 200 ) ;
34
34
assert . htmlEqual ( target . innerHTML , '<button>toggle</button><p style="">delayed fade</p>' ) ;
35
35
36
- // TODO this doesn't work because for some reason opacity of the element is always 0
37
36
// out
38
- // btn?.click();
39
- // flushSync();
40
- // raf.tick(275);
41
- // assert.htmlEqual(target.innerHTML, '<button>toggle</button><p style="">delayed fade</p>');
37
+ btn ?. click ( ) ;
38
+ flushSync ( ) ;
39
+ raf . tick ( 275 ) ;
40
+ assert . htmlEqual ( target . innerHTML , '<button>toggle</button><p style="">delayed fade</p>' ) ;
42
41
43
- // raf.tick(350);
44
- // assert.htmlEqual(
45
- // target.innerHTML,
46
- // '<button>toggle</button><p style="opacity: 0.5;">delayed fade</p>'
47
- // );
42
+ raf . tick ( 350 ) ;
43
+ assert . htmlEqual (
44
+ target . innerHTML ,
45
+ '<button>toggle</button><p style="opacity: 0.5;">delayed fade</p>'
46
+ ) ;
48
47
}
49
48
} ) ;
Original file line number Diff line number Diff line change 1
1
<script >
2
- import { fade } from ' svelte/transition' ;
2
+ function fade (_ ) {
3
+ return {
4
+ delay: 100 ,
5
+ duration: 100 ,
6
+ css : (t ) => ` opacity: ${ t} `
7
+ };
8
+ }
3
9
4
10
let visible = $state (false );
5
11
</script >
6
12
7
13
<button onclick ={() => (visible = ! visible )}>toggle</button >
8
14
9
15
{#if visible }
10
- <!-- explicit opacity necessary for some reason, else it's calculated as 0 -->
11
- <p transition:fade ={{ delay : 100 , duration : 100 }} style =" opacity: 1" >delayed fade</p >
16
+ <p transition:fade >delayed fade</p >
12
17
{/if }
You can’t perform that action at this time.
0 commit comments