javascript - window.screenX/screenY 没有在 chrome 上更新

标签 javascript html google-chrome window screen

我创建了这个小测试页,循环打印 window.screenX 和 screenY,它无法更新 chrome 上的值

Version 67.0.3396.79 (Official Build) (64-bit) on mac

(在 Safari 和 FF 上运行良好):

const wrapper = document.getElementById('wrapper');
const wrapperClick = document.getElementById('wrapperClick');

document.body.addEventListener('click',(e) => {
  wrapperClick.innerText = `${ window.screenX }, ${ window.screenY }, ${ window.innerWidth } × ${ window.innerHeight }`;
});

function refreshLoop() {
  window.requestAnimationFrame(() => {
    wrapper.innerText = `${ window.screenX }, ${ window.screenY }, ${ window.innerWidth } × ${ window.innerHeight }, ${ Math.random().toFixed(2) }`;
    
    refreshLoop();
  });
}

refreshLoop();
body {
  margin: 0;
  height: 100vh;
}

#wrapper,
#wrapperClick {
  position: fixed;
  top: 16px;
  left: 16px;
  font-family: monospace;
  font-size: 18px;
  line-height: 20px;
}

#wrapperClick {
  top: 52px;
}
<div id="wrapper"></div>
<div id="wrapperClick"></div>

这是 Chrome 的错误吗?

最佳答案

在 Mac 上的 Chrome 67.0.3396.62 上测试它时,值会正确更新,但只有在您停止调整窗口大小/移动窗口后才会更新,这是当前的行为。

自 2014 年初报告并请求更改以来,一直存在一个问题:

screenX and screenY parameters don't update until you pause dragging

What steps will reproduce the problem?

  1. Launch sample app (attached).
  2. Drag it around.

Notice that the screenX and screenY only update after you stop moving the mouse. This is inconsistent with the behaviour of the innerWidth and innerHeight which update during resizing.

A much more useful behaviour would be if the screenX and screenY parameters updated during a drag, not just at the end of it.

关于javascript - window.screenX/screenY 没有在 chrome 上更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50781699/

相关文章:

google-chrome - https ://clients2. google.com/service/update2/crx 不再有效了吗?

java - 部分 CSS 代码在 Chrome 中不起作用

javascript - 获取json编码形式的信息

javascript - 在图表 js 中只想要线条而不是它下面的区域

javascript - 有没有办法在包含 html 的变量内循环

javascript - 通过匹配文本忽略特定的 JS 错误

javascript - 将 Children 属性传递给 React Memo 组件

javascript - 从选择框中选择月份名称和该特定月份的日期

Javascript 类 Getter Setter

javascript - 如何在angularjs中获取<select>中所选选项的索引