问题
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,
);
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?
回答1:
As above @Daniel A.White said, it because layerX and layerY are non-standard. The alternative option is offsetX and offsetY.
来源:https://stackoverflow.com/questions/59340676/how-can-i-set-an-event-type-for-layerx-and-layery