ScreenDetailed: devicePixelRatio 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

ScreenDetailed 接口中只读的 devicePixelRatio 属性是一个数字,表示屏幕的 设备像素 比。

这与 Window.devicePixelRatio 返回的值相同,不同的是 Window.devicePixelRatio

  • 始终返回 当前屏幕 的设备像素比。
  • 还包括窗口本身的缩放,即页面缩放(至少在某些浏览器实现中是这样)。

一个数字。

示例

js
const screenDetails = await window.getScreenDetails();

// Return the device pixel ratio of the first screen
const screen1DPR = screenDetails.screens[0].devicePixelRatio;

规范

规范
窗口管理
# ref-for-dom-screendetailed-devicepixelratio

浏览器兼容性

另见