[英]Mousemove on pointer-events none div
How do i trigger the mousemove event on a pointer-events none div, I can't edit the html of the page only the javascript (banking) 如何在指针事件无div上触发mousemove事件,我只能编辑javascript(银行)页面的html
<h1>title</h1>
<div class="wrapper">
<h3>element 1</h3>
<h3>element 2</h3>
</div>
the script currently only triggers the body as the target and not the element 该脚本当前仅触发主体作为目标,而不触发元素
document.body.addEventListener("mousemove", function(e) {
console.log(e.target)
})
https://codepen.io/anon/pen/PxOMQL https://codepen.io/anon/pen/PxOMQL
I think this is what you're looking for. 我认为这就是您要寻找的。 Once mouse moves over anything that is inside div with class wrapper, it will log it.
一旦鼠标移动到具有类包装器的div内的任何内容上,它将对其进行记录。
let wrappers = document.getElementsByClassName("wrapper"); for ( let i = 0; i < wrappers.length; i++ ) { wrappers[ i ].style.pointerEvents = "auto"; wrappers[ i ].addEventListener( "mousemove", function(e){ console.log( e.target ); }); }
.wrapper { pointer-events: none; }
<h1>title</h1> <div class="wrapper"> <h3>element 1</h3> <h3>element 2</h3> </div>
EDIT: You could overwrite the CSS class of wrapper with JavaScript to set pointer-events to auto, otherwise mouse events will not work while it is set to none in CSS. 编辑:您可以使用JavaScript覆盖包装器的CSS类,以将指针事件设置为自动,否则,在CSS中将鼠标事件设置为none时,鼠标事件将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.