[removed] Capture mouse wheel event and do not scroll the page?

前端 未结 5 670
逝去的感伤
逝去的感伤 2020-11-28 13:29

I\'m trying to prevent a mousewheel event captured by an element of the page to cause scrolling.

I expected false as last parameter to have the expected

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 13:58

    Have you tried event.preventDefault() to prevent the event's default behaviour?

    this.canvas.addEventListener('mousewheel',function(event){
        mouseController.wheel(event);
        event.preventDefault();
    }, false);
    

    Keep in mind that nowadays mouswheel is deprecated in favor of wheel, so you should use

    this.canvas.addEventListener('wheel',function(event){
        mouseController.wheel(event);
        event.preventDefault();
    }, false);
    

提交回复
热议问题