2017-03-18 2 views
0

내가 클릭 이벤트 이후 마우스 오버와로 마우스 기능을 중지하려고 노력했지만 작동하지 않습니다클릭 이벤트 이후 마우스 오버와로 마우스 기능을 중지하는 방법

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').; 
     }) 

내가 뭘하려고 해요하여 재생하는 것입니다 클릭 한 후 소리가 나는 비디오. 대신 마우스 오버 효과가 계속됩니다.

감사합니다. 나쁜 영어

+0

'NodeList.forEach()'([모든 브라우저에서 사용할 수]되지 않습니다 https://developer.mozilla.org/en -US/docs/Web/API/NodeList/forEach # Browser_Compatibility)'this'는 일반적인 DOM 노드이며 jQuery 객체가 아니므로'.off()'메소드가 없습니다 (브라우저가 콘솔). ['.addEventListener()'] (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)의 대응 부분을 찾으십시오. – Andreas

답변

0

사용 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); 
     }) 
관련 문제