如何为 'layerX' 设置事件类型和 'layerY'
问题描述:
我正在制作一个具有绝对位置的下拉菜单.它从鼠标事件中获取 x, y 坐标.
I'm making a dropdown menu having an absolute position. It gets x, y coordiation from mouse event.
container.addEventListener(
'contextmenu',
(e: MouseEvent) => {
drawingMenuX = e.layerX + 15; // chartiq basic padding is 15
drawingMenuY = e.layerY + 15;
},
false,
);
但它显示错误属性 'layerX' 在类型 'MouseEvent'.ts(2339) 上不存在".如何设置正确的事件类型而不是 MouseEvent?
But it show error "Property 'layerX' does not exist on type 'MouseEvent'.ts(2339)". How can I set a correct event type instead of MouseEvent?
答
如上@Daniel A.White 所说,因为 layerX 和 layerY 是非标准的.替代选项是 offsetX 和 offsetY.
As above @Daniel A.White said, it because layerX and layerY are non-standard. The alternative option is offsetX and offsetY.