vue.ts 799 B

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