From 8adff6d425b92c678fc54af49894284dffb4c315 Mon Sep 17 00:00:00 2001 From: hdx Date: Thu, 8 Aug 2024 18:04:10 +0800 Subject: [PATCH] =?UTF-8?q?AnimationFrame:=20=E5=A2=9E=E5=8A=A0=E5=B8=A7?= =?UTF-8?q?=E7=8E=87=E7=9A=84=E8=80=97=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/animation-frame/animation-frame.uvue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pages/API/animation-frame/animation-frame.uvue b/pages/API/animation-frame/animation-frame.uvue index 4d1ea94c..f9502ee7 100644 --- a/pages/API/animation-frame/animation-frame.uvue +++ b/pages/API/animation-frame/animation-frame.uvue @@ -3,7 +3,7 @@ - FPS: {{fps}} + FPS: {{fps}} / {{formatFPSTime}} FrameCount: {{testFrameCount}} 提示: 在当前测试例子中,每增加一次调用 requestAnimationFrame 帧率翻倍,cancelAnimationFrame 后恢复 @@ -15,7 +15,8 @@ return { title: 'AnimationFrame', taskId: 0, - fps: 0, + fps: 0, + formatFPSTime: '0ms', lastTime: 0, frameCount: 0, testFrameCount: 0 @@ -30,7 +31,8 @@ startRequestAnimationFrame() { this.taskId = requestAnimationFrame((timestamp : number) => { this.frameCount++ - if (timestamp - this.lastTime >= 1000) { + if (timestamp - this.lastTime >= 1000) { + this.formatFPSTime = (1000 / this.frameCount).toFixed(3) + 'ms' this.fps = this.frameCount this.frameCount = 0 this.lastTime = timestamp @@ -42,6 +44,7 @@ }, stopRequestAnimationFrame() { this.fps = 0 + this.formatFPSTime = '0ms' this.lastTime = 0 this.frameCount = 0 cancelAnimationFrame(this.taskId) -- GitLab