WP博客添加实时显示FPS帧率代码

教程评论7791字数 1099阅读3分39秒阅读模式

网页上实时显示 FPS(每秒帧数)帧率,不知道有什么用,可能好的电脑才能看出区别吧。

 

WP博客添加实时显示FPS帧率代码
JS代码随便找个地方就行了
  1. <script>
  2.     jQuery(document).ready(function($){
  3.     $('body').before('<div id="fps" style="position: fixed;right: 20px;color: #fff;line-height: 1;z-index:10000;padding: 5px 8px;"></div>');
  4.     var showFPS = (function() {
  5.         var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
  6.         function(callback) {
  7.             window.setTimeout(callback, 1000 / 60);
  8.         };
  9.         var e, pe, pid, fps, last, offset, step, appendFps;
  10.         fps = 0;
  11.         last = Date.now();
  12.         step = function() {
  13.             offset = Date.now() - last;
  14.             fps += 1;
  15.             if (offset >= 1000) {
  16.                 last += offset;
  17.                 appendFps(fps);
  18.                 fps = 0;
  19.             }
  20.             requestAnimationFrame(step);
  21.         };
  22.         appendFps = function(fps) {
  23.             console.log(fps + ' FPS');
  24.             $('#fps').html(fps + ' FPS');
  25.         };
  26.         step();
  27.     })();
  28. });
  29. </script>

我的微信
微信扫一扫
weinxin
我的微信
我的微信公众号
微信扫一扫
weinxin
我的公众号
 
  • 本文由 夏沫 发表于 2023年10月27日23:05:20
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证