2017-05-18 1 views
-1

div 또는 div의 요소 위에 마우스가있을 때 마우스 휠 이벤트를 캡처하여 페이지가 스크롤되지 않도록해야합니다.Javascript - 페이지 스크롤을 막는 동안 마우스 휠 캡처

이 포럼에는 몇 가지 해결책이 있지만 (예 : thisthis) 페이지가 계속 스크롤됩니다.

솔루션은 순수한 자바 스크립트 (즉, JQuery가 아니어야 함) 여야합니다.

유용한 제안/해결책을 제공해 주시면 대단히 감사하겠습니다.

답변

2

캡처 한 후 이벤트를 취소하기 만하면됩니다.

// This disables the event for the entire document. 
 
// Substitute a reference to the DOM element you wish to 
 
// deal with instead of "document" below. 
 
document.addEventListener("mousewheel", function(evt){ 
 

 
    console.log("mousewheel event detected"); 
 

 
    evt.preventDefault(); // Cancel the event 
 
    evt.stopPropagation() // Don't bubble 
 

 
});

+0

빙고 !!!! 감사합니다 스콧 !!! – FDavidov

관련 문제