提交 cf185672 编写于 作者: H hdx

cancelAnimationFrame: 增加帧率计算并显示

上级 283a36b9
......@@ -3,7 +3,9 @@
<page-head :title="title"></page-head>
<button @click="startRequestAnimationFrame">requestAnimationFrame</button>
<button @click="stopRequestAnimationFrame">cancelAnimationFrame</button>
<text class="frame-count">{{testFrameCount}}</text>
<text class="frame-count">FPS: {{fps}}</text>
<text class="frame-count">FrameCount: {{testFrameCount}}</text>
<text class="tips">提示: 在当前测试例子中,调用一次 requestAnimationFrame 帧率翻倍,cancelAnimationFrame 后恢复</text>
</view>
</template>
......@@ -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;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册