init
This commit is contained in:
12
uni_modules/lime-shared/raf/index.ts
Normal file
12
uni_modules/lime-shared/raf/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// @ts-nocheck
|
||||
|
||||
// #ifdef UNI-APP-X && APP
|
||||
// export * from './uvue'
|
||||
export { raf, doubleRaf, cancelRaf } from './uvue'
|
||||
// #endif
|
||||
|
||||
|
||||
// #ifndef UNI-APP-X && APP
|
||||
// export * from './vue'
|
||||
export { raf, doubleRaf, cancelRaf } from './vue'
|
||||
// #endif
|
48
uni_modules/lime-shared/raf/uvue.uts
Normal file
48
uni_modules/lime-shared/raf/uvue.uts
Normal file
@@ -0,0 +1,48 @@
|
||||
// @ts-nocheck
|
||||
// 是否支持被动事件监听
|
||||
export const supportsPassive = true;
|
||||
|
||||
// #ifdef uniVersion < 4.25
|
||||
// 请求动画帧
|
||||
export function raf(fn: TimerCallback): number {
|
||||
return setTimeout(fn, 1000 / 60);
|
||||
}
|
||||
|
||||
// 取消动画帧
|
||||
export function cancelRaf(id: number) {
|
||||
clearTimeout(id);
|
||||
}
|
||||
|
||||
|
||||
// 双倍动画帧
|
||||
export function doubleRaf(fn: TimerCallback): void {
|
||||
raf(():number => raf(fn)); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
|
||||
}
|
||||
// #endif
|
||||
|
||||
|
||||
// #ifdef uniVersion >= 4.25
|
||||
// 请求动画帧
|
||||
export function raf(fn: UniAnimationFrameCallback): number
|
||||
export function raf(fn: UniAnimationFrameCallbackWithNoArgument): number
|
||||
export function raf(fn: any): number {
|
||||
if(typeof fn == 'UniAnimationFrameCallback') {
|
||||
return requestAnimationFrame(fn as UniAnimationFrameCallback);
|
||||
} else {
|
||||
return requestAnimationFrame(fn as UniAnimationFrameCallbackWithNoArgument);
|
||||
}
|
||||
}
|
||||
|
||||
// 取消动画帧
|
||||
export function cancelRaf(id: number) {
|
||||
cancelAnimationFrame(id);
|
||||
}
|
||||
|
||||
// 双倍动画帧
|
||||
export function doubleRaf(fn: UniAnimationFrameCallback): void
|
||||
export function doubleRaf(fn: UniAnimationFrameCallbackWithNoArgument): void
|
||||
export function doubleRaf(fn: any): void {
|
||||
raf(():number => raf(fn)); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
|
||||
}
|
||||
// #endif
|
||||
|
32
uni_modules/lime-shared/raf/vue.ts
Normal file
32
uni_modules/lime-shared/raf/vue.ts
Normal file
@@ -0,0 +1,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)
|
||||
}); // 在下一帧回调中再次请求动画帧,实现双倍动画帧效果
|
||||
}
|
Reference in New Issue
Block a user