feat: 初始化
This commit is contained in:
10
uni_modules/lime-shared/raf/index.ts
Normal file
10
uni_modules/lime-shared/raf/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
// @ts-nocheck
|
||||
|
||||
// #ifdef APP-IOS || APP-ANDROID
|
||||
export * from './vue.ts'
|
||||
// #endif
|
||||
|
||||
|
||||
// #ifndef APP-IOS || APP-ANDROID
|
||||
export * from './uvue.ts'
|
||||
// #endif
|
20
uni_modules/lime-shared/raf/uvue.ts
Normal file
20
uni_modules/lime-shared/raf/uvue.ts
Normal file
@ -0,0 +1,20 @@
|
||||
// @ts-nocheck
|
||||
// import {isBrowser} from '../isBrowser'
|
||||
|
||||
// 是否支持被动事件监听
|
||||
export const supportsPassive = true;
|
||||
|
||||
// 请求动画帧
|
||||
export function raf(fn: TimerCallback): number {
|
||||
return setTimeout(fn, 1000 / 30);
|
||||
}
|
||||
|
||||
// 取消动画帧
|
||||
export function cancelRaf(id: number) {
|
||||
clearTimeout(id);
|
||||
}
|
||||
|
||||
// 双倍动画帧
|
||||
export function doubleRaf(fn: TimerCallback): void {
|
||||
raf(() => raf(fn)); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
|
||||
}
|
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