My current code is

我目前的代码是

document.addEventListener('click', function(event) {
    console.log(event.pageX + "-" + event.pageY);
});

however, there is a zoom set on the body (although I've no control over it, sometimes it's not there) and event.pageX and event.pageY are coming out wrong.

然而,身体上有一个缩放设置(虽然我无法控制它,有时它不存在),而event.pageX和event.pageY出错了。

Is there a way to get a relative value or something?

有没有办法获得相对价值或什么?

Edit:

编辑:

The css on the body is

身上的css是

body {
    zoom: 0.485417;
}

The zoom value may change (as part of some external JS - I've no control over that value, my JS doesn't set it, and it can change)

缩放值可能会改变(作为一些外部JS的一部分 - 我无法控制该值,我的JS没有设置它,它可以改变)

1 个解决方案

#1


2

I nailed this with the help of andlrc's comment:

我在andlrc的评论的帮助下钉了这个:

var zoomLevel = getComputedStyle(document.body).zoom;
if (zoomLevel <= 0) { zoomLevel = 0.1; }
doMyThing(event.pageX / zoomLevel, event.pageY / zoomLevel);

x and y passed in to "doMyThing" is now properly positioned, regardless of what the zoom is set to.

无论缩放设置为什么,传入“doMyThing”的x和y现在都已正确定位。

更多相关文章

  1. 缩放图像后的鼠标位置(比率/比率)
  2. android项目 之 记事本(14) ----- 手势缩放与拖拽图片
  3. 如何设置webview的初始缩放/宽度
  4. Button点击缩放动画效果
  5. Android开发学习之ImageView手势拖拽、缩放、旋转
  6. Android如何缩放应用中的字体大小
  7. android 关于webview缩放和适应屏幕的问题
  8. 3D相机缩放并遵循java中的物理特性?
  9. 是否有缩放因子方法用于Android的多分辨率支持

随机推荐

  1. android 过渡动画研究
  2. Android SAX 解析XML的Demo
  3. android sqlite 数据类型
  4. android 树形目录
  5. 下载Android SDK tools完成Android SDK
  6. Android小项目之 where are you 监控
  7. 一看就懂的Android APP开发入门教程
  8. 屏和竖屏切换是否调用Activity生命周期在
  9. 深入理解 Android 系统升级
  10. eclipse中开发Android出现问题解决记录和