@@ -31,24 +31,33 @@ if (!window.performance) window.performance = { now: Date.now.bind(Date) };
3131if ( ! window . requestAnimationFrame ) window . requestAnimationFrame = function ( cb ) { return setTimeout ( doAnim , cb ) ; } ;
3232function doAnim ( cb ) { cb ( performance . now ( ) ) ; }
3333
34- function ripple ( evt ) {
35- var button = this ,
34+ function ripple ( button , evt ) {
35+ var request ,
3636 rect = button . getBoundingClientRect ( ) ,
3737 x = evt . clientX - rect . left ,
3838 y = evt . clientY - rect . top ,
3939 start = performance . now ( ) ;
4040 button . classList . add ( 'animating' ) ;
41- requestAnimationFrame ( function raf ( now ) {
41+ request = requestAnimationFrame ( function raf ( now ) {
4242 var count = Math . floor ( now - start ) ;
4343 button . style . cssText = '--ripple-x: ' + x + '; --ripple-y: ' + y + '; --animation-tick: ' + count + ';' ;
4444 if ( count > 1000 ) {
4545 button . classList . remove ( 'animating' ) ;
4646 button . style . cssText = '--animation-tick: 0;' ;
4747 return ;
4848 }
49- requestAnimationFrame ( raf ) ;
50- } )
49+ request = requestAnimationFrame ( raf ) ;
50+ } ) ;
51+ return function ( ) {
52+ cancelAnimationFrame ( request ) ;
53+ }
5154}
5255[ ] . forEach . call ( document . querySelectorAll ( '.ripple' ) , function ( el ) {
53- el . addEventListener ( 'click' , ripple ) ;
54- } ) ;
56+ var cancelRipple ;
57+ el . addEventListener ( 'click' , function ( evt ) {
58+ if ( cancelRipple ) {
59+ cancelRipple ( ) ;
60+ }
61+ cancelRipple = ripple ( this , evt ) ;
62+ } ) ;
63+ } ) ;
0 commit comments