简体   繁体   English

为什么Firefox event.offsetX和offsetY未定义?

[英]Why Firefox event.offsetX and offsetY are undefined?

I just stumbled upon a bug in my software that happened only on Firefox. 我只是偶然发现我的软件中只出现在Firefox上的一个错误。 The reason was that the event didn't have offsetX and offsetY defined. 原因是该事件没有定义offsetX和offsetY。

I managed to fix it thanks to this . 由于这个原因,我设法解决了这个问题

Anyways, my question is not a programming help request. 无论如何,我的问题不是编程帮助请求。 I'm just curious why these properties are undefined in Firefox? 我只是好奇为什么这些属性在Firefox中未定义? What is the reason behind it? 它背后的原因是什么?

I did look through: DOM3 UIEvent Spec. 我确实看过: DOM3 UIEvent Spec。 , DOM3 MouseEvent Spec. DOM3 MouseEvent Spec。 and DOM2 MouseEvent Spec. DOM2 MouseEvent Spec。 .

It appears that neither of the properties are mentioned there, so, I suppose that's an unofficial property introduced in other browsers? 似乎这里没有提到任何属性,所以,我认为这是在其他浏览器中引入的非官方属性?

Although mentioned in the W3 specification , the offsetx / offsety properties themselves are implemented inconsistently across browsers. 虽然在W3规范中提到过, offsetx / offsety属性本身在浏览器中实现不一致。

While supported in IE, Webkit browsers and Opera, they all function slightly different to the specifications requirements, except for IE - according to the "Calculating offsetX, offsetY" section here . 虽然在IE,Webkit浏览器和Opera中都受到支持,但它们的功能都略有不同,除了IE之外 - 根据此处的“计算offsetX,offsetY”部分

The properties aren't supported in Firefox at all - it appears to be a long-time bug that is yet to be resolved. Firefox中根本不支持这些属性 - 它似乎是一个尚未解决的长期错误

"I suppose that's an unofficial property introduced in other browsers?" “我想这是在其他浏览器中引入的非官方属性?”

I believe it's an official property, that just hasn't been implemented in Firefox. 我相信它是一个官方财产,在Firefox中尚未实现。 If it was a non-official IE property, it wouldn't have been implemented in the Webkit/Opera browsers, mentioned in the W3 spec nor would Firefox actually be trying to implement it (check out the bug link above). 如果它是一个非官方的IE属性,它将不会在W3规范中提到的Webkit / Opera浏览器中实现,也不会实际尝试实现它(请查看上面的bug链接)。

offsetX and offsetY are inconsistent in Firefox so you can do it this way offsetX和offsetY在Firefox中不一致,所以你可以这样做

document.body.onclick = function(e) {
    e = e || window.event;

    var target = e.target || e.srcElement,
        rect = target.getBoundingClientRect(),
        offsetX = e.clientX - rect.left,
        offsetY = e.clientY - rect.top;

    console.log([offsetX, offsetY]);
};

You can find more info Here and here 你可以在这里这里找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firefox 中的 event.offsetX - event.offsetX in Firefox 为什么在“ touchstart”事件时未定义“ event.offsetX”? - Why is “event.offsetX” undefined when “touchstart” event? 将event.offsetX和event.offsetY的坐标转换为WebGL本机坐标 - Convert coordinates from event.offsetX and event.offsetY into webGL native coordinates 为什么 event.offsetX/Y 在 Firefox/Edge 与 Chrome 中提供不同的值? - Why does event.offsetX/Y provide different values in Firefox/Edge vs Chrome? mousemove期间的event.offsetX - event.offsetX during mousemove 为什么 offsetX 和 offsetY 在 firefox 和 chrome 中返回不同的值 - why offsetX and offsetY return different value in firefox and chrome 为什么我的事件处理程序中的 offsetX 和 offsetY 出错了? - Why am I getting wrong offsetX and offsetY in my event handler? 父元素的mousedown事件上的offsetX和offsetY错误 - Wrong offsetX and offsetY on mousedown event of parent element 鼠标移动事件返回1时,translateX = event.offsetX setter - translateX = event.offsetX setter on mousemove event return 1 - sometimes 如何使用offsetX和offsetY在firefox浏览器中的svg内移动一个圆圈? - How to move a circle inside a svg in the firefox browser with offsetX and offsetY?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM