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