@@ -2,11 +2,7 @@ const duration = 600
2
2
const easeOutQuad = t => t * ( 2 - t )
3
3
4
4
function css ( element , styles ) {
5
- for ( const property in styles ) {
6
- if ( ! styles . hasOwnProperty ( property ) ) {
7
- continue
8
- }
9
-
5
+ for ( const property of Object . keys ( styles ) ) {
10
6
element . style [ property ] = styles [ property ]
11
7
}
12
8
}
@@ -89,17 +85,13 @@ function toggle (element, animation) {
89
85
}
90
86
}
91
87
92
- function animate ( element , targetStyles , fn ) {
88
+ function animate ( element , targetStyles , callbackFn ) {
93
89
let startTime = null
94
90
const styles = window . getComputedStyle ( element )
95
91
const diff = { }
96
92
const startStyles = { }
97
93
98
- for ( const property in targetStyles ) {
99
- if ( ! targetStyles . hasOwnProperty ( property ) ) {
100
- continue
101
- }
102
-
94
+ for ( const property of Object . keys ( targetStyles ) ) {
103
95
// calculate step size & current value
104
96
const to = parseFloat ( targetStyles [ property ] )
105
97
const current = parseFloat ( styles [ property ] )
@@ -117,22 +109,19 @@ function animate (element, targetStyles, fn) {
117
109
if ( ! startTime ) startTime = timestamp
118
110
const progress = Math . min ( ( timestamp - startTime ) / duration , 1.00 )
119
111
120
- for ( const property in diff ) {
121
- if ( ! diff . hasOwnProperty ( property ) ) {
122
- continue
123
- }
124
-
112
+ for ( const property of Object . keys ( diff ) ) {
125
113
const suffix = property !== 'opacity' ? 'px' : ''
126
114
element . style [ property ] = startStyles [ property ] + ( diff [ property ] * easeOutQuad ( progress ) ) + suffix
127
115
}
128
116
117
+ // keep going until animation finished
129
118
if ( progress < 1.00 ) {
130
119
return window . requestAnimationFrame ( tick )
131
120
}
132
121
133
122
// animation finished!
134
- if ( fn ) {
135
- fn ( )
123
+ if ( callbackFn ) {
124
+ callbackFn ( )
136
125
}
137
126
}
138
127
0 commit comments