当前位置: 首页 > article >正文

HTML 计算网页的PPI

HTML 计算网页的PPI

vscode上安装live server插件,可以实时看网页预览
有个疑问: 鸿蒙density是按照类别写死的吗,手机520dpi 折叠屏426dpi 平板360dpi

<html lang="en" data - overlayscrollbars - initialize><header></header><body><div><div id="messageID">heheh</div></div><script>function getdpi2() {const dpr = window.devicePixelRatio || 1;const measureDiv = document.createElement("inchUnitId");measureDiv.style.cssText = `width: 1in;height: 1in;border - color: blue;position: absolute;top: 0;left: 0;display: flex;`;document.body.appendChild(measureDiv);window.getComputedStyle(measureDiv).width;window.getComputedStyle(measureDiv).height;const cssWidth = measureDiv.offsetWidth;const cssHeight = measureDiv.offsetHeight;const physicalWidth = cssWidth / dpr;const physicalHeight = cssHeight / dpr;const dpx = Math.round(physicalWidth);const dpy = Math.round(physicalHeight);const screenWidth = window.screen.width * dpr;const screenHeight = window.screen.height * dpr;const screenRatio = (screenWidth / screenHeight).toFixed(4);const ppi = (Math.sqrt(Math.pow(physicalWidth, 2) + Math.pow(physicalHeight, 2)) /Math.sqrt(2)).toFixed(4);const vppi = (ppi / 160).toFixed(4);// 手机ppi 应为 528dpiconst phonePPI =Math.sqrt(Math.pow(1280, 2) + Math.pow(2720, 2)) / 6.82;const phoneVPPX = (phonePPI / 160).toFixed(4);// 平板ppi应为 366dpiconst tablePPI =Math.sqrt(Math.pow(2560, 2) + Math.pow(1600, 2)) / 10.8;const tableVPPX = (tablePPI / 160).toFixed(4);// foldablePPI 应为 224dpiconst foldablePPI =Math.sqrt(Math.pow(2224, 2) + Math.pow(2406, 2)) / 7.85;const foldableVPPX = (foldablePPI / 160).toFixed(4);const messageID = document.getElementById("messageID");messageID.innerHTML = `<p>dpx:${dpx}</p>                                                                                                                                      <p>dpy:${dpy}</p><p>ppi:${ppi}</p><p>phonePPI:${phonePPI}  phoneVPPX:${phoneVPPX}</p><p>tablePPI:${tablePPI}  tableVPPX:${tableVPPX}</p><p>foldablePPI:${foldablePPI}  foldableVPPX:${foldableVPPX}</p><p>vppx:${vppi}</p><p>devicePixelRatio:${devicePixelRatio}</p><p>physicalWidth:${physicalWidth}</p><p>physicalHeight:${physicalHeight}</p><p>window.screen.width:${window.screen.width}</p><p>window.screen.height:${window.screen.height}</p>`;document.body.removeChild(measureDiv);}setInterval(() => {getdpi2();}, 200);</script></body>
</html>

在这里插入图片描述

http://www.lryc.cn/news/2394950.html

相关文章:

  • WIN11+eclipse搭建java开发环境
  • Linux 环境下C、C++、Go语言编译环境搭建秘籍
  • MMR-Mamba:基于 Mamba 和空间频率信息融合的多模态 MRI 重建|文献速递-深度学习医疗AI最新文献
  • 2.5/Q2,Charls最新文章解读
  • Unity QFramework 简介
  • C++ 日志系统实战第五步:日志器的设计
  • @Docker Compose部署Alertmanager
  • 前端面试准备-3
  • 性能测试-jmeter实战1
  • 汽车高速通信的EMC挑战
  • [SC]SystemC在CPU/GPU验证中的应用(五)
  • [蓝桥杯C++ 2024 国 B ] 立定跳远(二分)
  • 现代网络安全攻防技术与发展现状
  • 杏仁海棠花饼的学习日记第十四天CSS
  • ESP8266远程控制:实现网络通信与设备控制
  • RabbitMQ监控:关键技术、技巧与最佳实践
  • 【机器学习基础】机器学习入门核心算法:隐马尔可夫模型 (HMM)
  • zookeeper 操作总结
  • golang 实现基于redis的并行流量控制(计数锁)
  • Leetcode 2819. 购买巧克力后的最小相对损失
  • AI炼丹日志-25 - OpenAI 开源的编码助手 Codex 上手指南
  • AnyConv OGG 转换器:轻松转换音频格式
  • C# 类和继承(使用基类的引用)
  • 进程间通信(消息队列)
  • Linux gron 命令使用详解
  • Nginx--手写脚本压缩和切分日志(也适用于docker)
  • OpenCv高阶(十八)——dlib人脸检测与识别
  • 中山大学无人机具身导航新突破!FlightGPT:迈向通用性和可解释性的无人机视觉语言导航
  • WIN11+CUDA11.8+VS2019配置BundleFusion
  • WPF prism