diff --git a/pages/API/cancel-animation-frame/cancel-animation-frame.uvue b/pages/API/cancel-animation-frame/cancel-animation-frame.uvue
index 2f0062c5b0bfb0796aaf0c633284c52f9162d912..074f46c711ff2d7c76c98afa9d1e7427f4bb9d74 100644
--- a/pages/API/cancel-animation-frame/cancel-animation-frame.uvue
+++ b/pages/API/cancel-animation-frame/cancel-animation-frame.uvue
@@ -3,7 +3,9 @@
- {{testFrameCount}}
+ FPS: {{fps}}
+ FrameCount: {{testFrameCount}}
+ 提示: 在当前测试例子中,调用一次 requestAnimationFrame 帧率翻倍,cancelAnimationFrame 后恢复
@@ -13,6 +15,9 @@
return {
title: 'cancelAnimationFrame',
taskId: 0,
+ lastTime: 0,
+ frameCount: 0,
+ fps: 0,
testFrameCount: 0
}
},
@@ -23,8 +28,14 @@
},
methods: {
startRequestAnimationFrame() {
- this.taskId = requestAnimationFrame((_ : number) => {
- this.testFrameCount++
+ this.taskId = requestAnimationFrame((timestamp : number) => {
+ this.testFrameCount++
+ this.frameCount++
+ if (timestamp - this.lastTime >= 1000) {
+ this.fps = this.frameCount
+ this.frameCount = 0
+ this.lastTime = timestamp
+ }
this.startRequestAnimationFrame()
})
},
@@ -42,5 +53,11 @@
.frame-count {
margin-top: 15px;
+ }
+
+ .tips {
+ font-size: 12px;
+ margin-top: 30px;
+ opacity: 0.7;
}