[英]How to stop mouseover and mouseout function after a click event
I have been trying to stop a mouseover and mouseout function after a click event but it does not work: 我一直试图在单击事件后停止mouseover和mouseout功能,但是它不起作用:
document.querySelectorAll('.box').forEach(function(x){
x.addEventListener("mouseover", function () {
video = this.querySelector('video');
if (video.muted == true) {
video.muted = false;
} else {
video.muted = true;}
}, false)
x.addEventListener("mouseout", function () {
this.querySelector('video').muted = true;
}, false)
x.addEventListener("click", function () {
this.off('mouseover').;
})
What i'm trying is to play the video with sound after a click, but instead, it continues with the mouseover effect. 我正在尝试的是单击后播放带声音的视频,但是它继续具有鼠标悬停效果。
Thank you! 谢谢! and sorry for bad english
对不起,英语不好
Use removeEventListener
to remove attached event handler 使用
removeEventListener
删除附加的事件处理程序
function mouseoverfunc() {
video = this.querySelector('video');
if (video.muted == true) {
video.muted = false;
} else {
video.muted = true;}
}
document.querySelectorAll('.box').forEach(function(x){
x.addEventListener("mouseover",mouseoverfunc, false)
x.addEventListener("mouseout", function () {
this.querySelector('video').muted = true;
}, false)
x.addEventListener("click", function () {
this.removeEventListener('mouseover',mouseoverfunc);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.