JavaScript计算当前屏幕尺寸的80%是多少像素

标签 javascript

我正在尝试计算当前屏幕尺寸的 80% 宽度有多少个像素。

这是我到目前为止所得到的:

    setInterval(function () {
        width = (window.innerWidth > 0) ? window.innerWidth : screen.width;

        var percentWidth = 0.2;
        var nWidth = (width - percentWidth) / width;   
        nWidth = Math.floor((nWidth * 100));


        console.log(nWidth);
    }, 100); 

知道哪里出了问题吗?

最佳答案

窗口宽度的 80%:

    window.innerWidth * .8

关于JavaScript计算当前屏幕尺寸的80%是多少像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20119208/

相关文章:

javascript - RxJS - 使具有重置无状态的计数器?

javascript - 由于误用状态,数组未动态更新

javascript - 将构造函数分配给变量。 - 为什么这段代码不起作用,使用 firefox 控制台

javascript - 使用 jest 模拟多个 axios 调用

javascript - 以编程方式单击Extjs中的按钮

javascript - Laravel 5.5 - CORS GET 请求更改为 OPTIONS

javascript - 将轨道添加到播放列表中Spotify api Web

javascript - 更新 npm 后 node_modules 中的错误?

javascript - Google Maps Api V3 - 国家或城市样式

javascript - 使用javascript获取包含GET变量的路径