UNPKG

logic-helper

Version:

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

32 lines (29 loc) 941 B
const requestAnimation = (() => { if(typeof requestAnimationFrame === 'function'){ return requestAnimationFrame } if(typeof window == 'undefined'){ return function (callback) { const time = Date.now(); return setTimeout(()=>{ callback(time) }, 1000 / 60); }; } return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { const time = Date.now(); return setTimeout(()=>{ callback(time) }, 1000 / 60); }; })(); export const animation = (callback, interval) => { let lastTime = 0; const loop = (time) => { callback(time - lastTime, () => { lastTime = time }); requestAnimation(loop); }; requestAnimation(loop); }