是否可以在JavaScript中通过浏览器检测硬件加速?

发布于 2024-10-26 17:19:23 字数 163 浏览 2 评论 0原文

我注意到,由于字体渲染发生变化,使用硬件加速的浏览器的字体大小并不相同 - 使字符显得更小。在具有水平导航的网站上,这实际上正在成为一个问题。

是否可以使用 JavaScript 或 JS 库来检测浏览器中是否启用(或禁用)硬件加速?

Modernizr 似乎没有提供这种选择。

I've noticed that font sizes are not the same across browsers which use hardware acceleration due to the font rendering changes - making characters appear smaller. On sites with horizontal navigation, this is actually becoming an issue.

Is it possible to use JavaScript or a JS library to detect hardware acceleration as being enabled (or disabled) in the browser?

Modernizr doesn't seem to offer this choice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

〆凄凉。 2024-11-02 17:19:23

字体呈现因浏览器、操作系统和用户设置而异。因此,您的网站应该优雅地处理此类差异,而不是依赖于像素精确的字体渲染。硬件加速只是造成这种差异的又一个原因。

由于您实际上并不是想知道它是否是硬件加速的,而是在字体渲染方面存在差异,那么如何测量某些渲染文本的大小,并据此调整您的页面呢?

The font rendering differs depending on browser, OS and user settings. So your website should deal with such differences gracefully instead of relying on pixel exact font rendering. Hardware acceleration is just one more source of such differences.

Since you're not actually interested in finding out if it is hardware accelerated, but in differences in font rendering how about measuring the size some rendered text has, and adapt your page based on that?

澜川若宁 2024-11-02 17:19:23

由于您只对跨浏览器和平台的字体大小差异感兴趣,因此可能值得研究字体大小标准化技术。

我个人唯一熟悉的是 YUI Fonts CSS。我在所有项目中都使用它,并且使用了 HTML5Boilerplate 项目。

还有 CSS 排版框架,例如 BaselineTypogridphyBlueprint(我已经研究过这个,如果你去的话推荐它沿着这条路)最后是atatonic

Since you're only interested in the difference of font size across browsers and platforms, it might be worth looking into font size normalizing techniques.

The only one I'm personally familiar with is YUI Fonts CSS. I use it in all my projects and it's used the HTML5Boilerplate project.

There are also css typography frameworks such as the Baseline, Typogridphy, Blueprint (I've looked into this a recommend it if you go down this path) and finally atatonic

谜兔 2024-11-02 17:19:23

与其寻找缓慢渲染的解决方法,为什么不使用 underscore 的节流或反跳来减少刷新呢?

Rather than have workarounds for slow rendering, why not use underscore's throttle or debounce to reduce refreshes?

往昔成烟 2024-11-02 17:19:23
<script type="text/javascript">
<!--
window.onload=function(){
        if(window.screen.availHeight>700 && window.screen.availWidth>1000)
        {
        document.body.style.fontSize="15px";
        }
.................
//another conditions
}
//-->
</script>

您无法获得处理器速度或内存大小
但你可以通过函数来​​了解硬件强度

<script type="text/javascript">  

 var number=10;  
 var i;  
 var start = (new Date).getTime();  
 //code here  
     for(i=0;i<10000;i++)  
     {  
      number=number*10;  
     }  
 var diff = (new Date).getTime() - start;  
 alert(diff);  

 start = (new Date).getTime();  
 //code here  
     while(i<10000)  
     {  
      number=number*10;  
      i++;  
     }  

diff = (new Date).getTime() - start;  
alert(diff);  

 </script> 
<script type="text/javascript">
<!--
window.onload=function(){
        if(window.screen.availHeight>700 && window.screen.availWidth>1000)
        {
        document.body.style.fontSize="15px";
        }
.................
//another conditions
}
//-->
</script>

you can't get processor speed or ram size
but you can make function to know the hardewre strength

<script type="text/javascript">  

 var number=10;  
 var i;  
 var start = (new Date).getTime();  
 //code here  
     for(i=0;i<10000;i++)  
     {  
      number=number*10;  
     }  
 var diff = (new Date).getTime() - start;  
 alert(diff);  

 start = (new Date).getTime();  
 //code here  
     while(i<10000)  
     {  
      number=number*10;  
      i++;  
     }  

diff = (new Date).getTime() - start;  
alert(diff);  

 </script> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文