-
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="fpsdom"></div> <button onclick="start()">开始</button> <button onclick="end()">结束</button> <script> var pwgl = { currrentTime: undefined, lastTime:undefined, fpsNum:0, fpsins: null } function tick(){ pwgl.currrentTime = Date.now(); if(pwgl.lastTime === undefined) { pwgl.lastTime = Date.now(); } if(pwgl.currrentTime - pwgl.lastTime >= 1000) { fpsdom.innerHTML = pwgl.fpsNum; pwgl.fpsNum = 0; pwgl.lastTime = pwgl.currrentTime; } pwgl.fpsNum++; pwgl.fpsins = requestAnimationFrame(tick); } function start(){ if(pwgl.fpsins === null) { tick(); } } function end(){ cancelAnimationFrame(pwgl.fpsins); pwgl.fpsins = null; pwgl.lastTime = undefined; pwgl.fpsNum = 0; } </script> </body> </html>
-
标签:currrentTime,FPS,fpsins,计算,fpsNum,lastTime,pwgl,undefined From: https://www.cnblogs.com/fqh123/p/18248758