简体   繁体   English

多层元素上的Mousedown事件[JavaScript]

[英]Mousedown event on multilayer elements [JavaScript]

I have a div element placed on top of a canvas (with absolute positioning). 我在画布上放置了一个div元素(具有绝对位置)。 Is there a way to make canvas.addEventListener('mousedown,......) work when the user clicks on the div element? 当用户单击div元素时,是否可以使canvas.addEventListener('mousedown,......)工作? I know logically it shouldn't worked as div is placed on top of canvas and user is ultimately clicking div element, not canvas. 我知道从逻辑上讲它不应该工作,因为div放置在画布上,并且用户最终单击div元素,而不是画布。 Will making div element transparent or something work? 使div元素透明或起作用吗? or is there any other possible solution to this problem? 还是对此问题有其他解决方案?

For newer browsers you can use CSS pointer-events 对于较新的浏览器,您可以使用CSS 指针事件

.div_class {pointer-events : none}

FIDDLE 小提琴

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM