vue.ts 843 B

123456789101112131415161718192021222324252627282930313233
  1. // @ts-nocheck
  2. // import { isBrowser } from '../isBrowser'
  3. type Callback = () => void//Function
  4. // 是否支持被动事件监听
  5. export const supportsPassive = true;
  6. // 请求动画帧
  7. export function raf(fn : Callback) : number {
  8. // #ifndef WEB
  9. return setTimeout(fn, 1000 / 30); // 请求动画帧
  10. // #endif
  11. // #ifdef WEB
  12. return requestAnimationFrame(fn); // 请求动画帧
  13. // #endif
  14. }
  15. // 取消动画帧
  16. export function cancelRaf(id : number) {
  17. // 如果是在浏览器环境下,使用 cancelAnimationFrame 方法
  18. // #ifdef WEB
  19. cancelAnimationFrame(id); // 取消动画帧
  20. // #endif
  21. // #ifndef WEB
  22. clearTimeout(id); // 取消动画帧
  23. // #endif
  24. }
  25. // 双倍动画帧
  26. export function doubleRaf(fn : Callback) : void {
  27. raf(() => {
  28. raf(fn)
  29. }); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
  30. }