File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -78,12 +78,22 @@ export default class Cube extends React.Component {
78
78
let degrees = 0 ;
79
79
let axis = 'y' ;
80
80
81
- this . _interval = setInterval ( ( ) => {
82
- let obj = { } ;
83
- obj [ axis ] = degrees += 90 ;
84
-
85
- this . setState ( { ...obj , iteration : ( this . state . iteration + 1 ) % 4 } ) ;
86
- } , repeatDelay ) ;
81
+ let lastTime = performance . now ( ) ;
82
+ let animation = ( ) => {
83
+ let nowTime = performance . now ( ) ;
84
+ let deltaTime = nowTime - lastTime ;
85
+
86
+ if ( repeatDelay <= deltaTime ) {
87
+ let obj = { } ;
88
+ obj [ axis ] = degrees += 90 ;
89
+
90
+ this . setState ( { ...obj , iteration : ( this . state . iteration + 1 ) % 4 } ) ;
91
+ lastTime = performance . now ( ) ;
92
+ }
93
+
94
+ this . _requestAnimation = requestAnimationFrame ( animation ) ;
95
+ } ;
96
+ animation ( ) ;
87
97
}
88
98
}
89
99
@@ -95,7 +105,7 @@ export default class Cube extends React.Component {
95
105
this . container . removeEventListener ( 'mouseleave' , this . listeners . reset ) ;
96
106
97
107
} else if ( continuous ) {
98
- clearInterval ( this . _interval ) ;
108
+ cancelAnimationFrame ( this . _requestAnimation ) ;
99
109
}
100
110
}
101
111
You can’t perform that action at this time.
0 commit comments