JavaScript 跨浏览器,高分辨率计时器功能(替换Date()。getTime())。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript 跨浏览器,高分辨率计时器功能(替换Date()。getTime())。相关的知识,希望对你有一定的参考价值。

var now = (function() {

  // Returns the number of milliseconds elapsed since either the browser navigationStart event or 
  // the UNIX epoch, depending on availability.
  // Where the browser supports 'performance' we use that as it is more accurate (microsoeconds
  // will be returned in the fractional part) and more reliable as it does not rely on the system time. 
  // Where 'performance' is not available, we will fall back to Date().getTime().

  var performance = window.performance || {};
    
  performance.now = (function() {
    return performance.now    ||
    performance.webkitNow     ||
    performance.msNow         ||
    performance.oNow          ||
    performance.mozNow        ||
    function() { return new Date().getTime(); };
  })();
          
  return performance.now();         

});

以上是关于JavaScript 跨浏览器,高分辨率计时器功能(替换Date()。getTime())。的主要内容,如果未能解决你的问题,请参考以下文章

C ++ Windows中的高分辨率计时器库? [复制]

C中的跨平台高分辨率计时器?

C++ 跨平台高分辨率计时器

实现高分辨率计时器的最佳方法

跨浏览器javascript下载功能

reedlau高精度 高分辨率 计时函数 Linux