WordPress添加FPS帧率显示[WP教程]

No matter when you start, it is important not to stop after the start.
无论你在什么时候开始,重要的是开始之后就不要停止

【活动】:会员128元永久会员早开早划算!

WordPress添加FPS帧率显示[WP教程]

WordPress添加FPS帧率显示[WP教程]

前言

我们经常打游戏时非常的关注游戏里的帧率的变化,游戏帧越低就越容易卡段,那么我们是否也可以给网站弄个FPS帧率显示呢?毋庸置疑当然可以啦,如果注意观察我网站的左上角,就会发现有xxFPS这几个字不断的发生变化,没错,它就是今天的主角FPS。其实非常的简单,只需一句js代码即可实现!今天就给大家分享一下WordPress添加帧率显示的教程,请往下看!

食用教程

  • 你只需在网站管理后台—》主题设置—》自定义代码—》自定义javascript代码,把下面的js代码复制粘贴到里面即可。
    // FPS帧
    $('body').before('<div id="fps" style="z-index:10000;position:fixed;top:3;left:3;font-weight:bold;"></div>');
    var showFPS = (function(){
    var requestAnimationFrame =
    window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    function(callback) {
    window.setTimeout(callback, 1000/60);
    };
    var e,pe,pid,fps,last,offset,step,appendFps;
    fps = 0;
    last = Date.now();
    step = function(){
    offset = Date.now() - last;
    fps += 1;
    if( offset >= 1000 ){
    last += offset;
    appendFps(fps);
    fps = 0;
    }
    requestAnimationFrame( step );
    };
    appendFps = function(fps){
    console.log(fps+'FPS');
    $('#fps').html(fps+'FPS');
    };
    step();
    })();
    // FPS帧 $('body').before('<div id="fps" style="z-index:10000;position:fixed;top:3;left:3;font-weight:bold;"></div>'); var showFPS = (function(){ var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000/60); }; var e,pe,pid,fps,last,offset,step,appendFps; fps = 0; last = Date.now(); step = function(){ offset = Date.now() - last; fps += 1; if( offset >= 1000 ){ last += offset; appendFps(fps); fps = 0; } requestAnimationFrame( step ); }; appendFps = function(fps){ console.log(fps+'FPS'); $('#fps').html(fps+'FPS'); }; step(); })();

     

WordPress添加FPS帧率显示[WP教程]
------本页已结束,新年特惠限时98元尊贵特权------

感谢您的来访,获取更多精彩文章请收藏本站。

Real dream is the other shore of reality.
真正的梦就是现实的彼岸
© 版权声明
THE END
点赞7打赏 分享
Whatever I believed, I did; and whatever I did, I did with my whole heart and mind.
凡是我相信的,我都做了;凡是我做了的事,都是全身心地投入去做的
评价 共1条

请登录后发表评论