File tree Expand file tree Collapse file tree 4 files changed +59
-15
lines changed Expand file tree Collapse file tree 4 files changed +59
-15
lines changed Original file line number Diff line number Diff line change
1
+ .vscode
Original file line number Diff line number Diff line change
1
+ class Flip {
2
+ constructor ( children ) {
3
+ this . #children = [ ...children ]
4
+ this . init ( )
5
+ }
6
+
7
+ #children;
8
+ #move = false ;
9
+ init ( ) {
10
+ if ( ! this . #children) return
11
+
12
+ this . #children. forEach ( ( child ) => {
13
+ const rect = child . getBoundingClientRect ( )
14
+ child . startX = rect . left
15
+ child . startY = rect . top
16
+ } )
17
+ }
18
+
19
+ /**
20
+ * 播放动画
21
+ * @param duration 动画时长 单位:毫秒
22
+ */
23
+ play ( change , { duration = 500 } ) {
24
+ if ( ! this . #children) return
25
+ if ( this . #move) return
26
+ this . #move = true ;
27
+
28
+ change ( )
29
+
30
+ this . #children. forEach ( ( child , i ) => {
31
+ const rect = child . getBoundingClientRect ( )
32
+ const lastX = rect . left
33
+ const lastY = rect . top
34
+
35
+ const animation = child . animate (
36
+ [
37
+ {
38
+ transform : `translate(${ child . startX - lastX } px,${ child . startY - lastY
39
+ } px)`,
40
+ } ,
41
+ {
42
+ transform : `none` ,
43
+ } ,
44
+ ] ,
45
+ {
46
+ duration,
47
+ id : `${ lastX } -${ lastY } -${ i } ` ,
48
+ }
49
+ )
50
+ animation . onfinish = ( ) => {
51
+ this . init ( )
52
+ this . #move = false
53
+ }
54
+ } )
55
+ }
56
+ }
57
+ window . Flip = Flip
Original file line number Diff line number Diff line change
1
+ # Flip翻转动画
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments