feat: 初始化
This commit is contained in:
33
uni_modules/lime-shared/raf/vue.ts
Normal file
33
uni_modules/lime-shared/raf/vue.ts
Normal file
@ -0,0 +1,33 @@
|
||||
// @ts-nocheck
|
||||
// import { isBrowser } from '../isBrowser'
|
||||
type Callback = () => void//Function
|
||||
// 是否支持被动事件监听
|
||||
export const supportsPassive = true;
|
||||
|
||||
// 请求动画帧
|
||||
export function raf(fn : Callback) : number {
|
||||
// #ifndef WEB
|
||||
return setTimeout(fn, 1000 / 30); // 请求动画帧
|
||||
// #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)
|
||||
}); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
|
||||
}
|
Reference in New Issue
Block a user