Created
          December 14, 2015 14:55 
        
      - 
      
 - 
        
Save wadackel/e961f951fb62c70e8ea2 to your computer and use it in GitHub Desktop.  
    ES6 ModulesでrequestAnimationFrameのpolyfill
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | let lastTime = 0; | |
| const raf = | |
| window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| function(callback){ | |
| const currentTime = Date.now(); | |
| const timeToCall = Math.max(0, 16 - (currentTime - lastTime)); | |
| const id = window.setTimeout(() => { callback(currentTime + timeToCall) }, timeToCall); | |
| lastTime = currentTime + timeToCall; | |
| return id; | |
| }; | |
| export default raf; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment