UNPKG

nuxt-countup

Version:

Nuxt 3 module for countup.js - A dependency-free, lightweight JavaScript class that can be used to quickly create animations that display numerical data in a more interesting way.

21 lines (20 loc) 498 B
import { ref } from "vue"; export function useRaf(cb, delaySeconds = 1) { const rafId = ref(-1); let startTime; function count(timestamp) { if (!startTime) startTime = timestamp; const diff = timestamp - startTime; if (diff < delaySeconds * 1e3) { rafId.value = requestAnimationFrame(count); } else { cb(); } } rafId.value = requestAnimationFrame(count); function cancel() { window.cancelAnimationFrame(rafId.value); } return { cancel }; }