本文介绍了如何修复属性"wheelDelta"在类型"WheelEvent"上不存在升级到有角度的7,rxjs6时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rxjs6升级到angular7:在mouseWheelEvent类型中,我得到"Property 'wheelDelta' does not exist on type 'WheelEvent'".

I'm upgrading to angular7 with rxjs6: in mouseWheelEvent type I am getting "Property 'wheelDelta' does not exist on type 'WheelEvent'".

我们是否可以替代wheelDelta?

mouseWheelFunc(event: MouseWheelEvent): void {

    //  var event = window.event || event; // old IE support

    let delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));

    if ( delta > 0) {
      this.mouseWheelUp.emit(event);
    } else if ( delta < 0) {
      this.mouseWheelDown.emit(event);
    }

    // for IE
    event.returnValue = false;
    // for Chrome and Firefox
    if ( event.preventDefault) {
      event.preventDefault();
    }
  }

推荐答案

WheelEvent似乎不再像上面所说的那样具有此属性.现在,他们添加了deltaY和deltaX.

It seems like WheelEvent doesn't have this property anymore as it says. Now they added deltaY and deltaX.

现在,您必须访问event.deltaY而不是event.wheelData.

Now you have to access event.deltaY instead of event.wheelData.

但是deltaY具有wheelData的相反值.这意味着当事件上的wheelData为正(向上滚动)时,deltaY将为负数,反之亦然.

But deltaY has the opposite value of wheelData. That means when wheelData on the event was positive (scroll up) deltaY will be a negative number, and vice versa.

示例:

更改此:

        zoomScroll(event: WheelEvent) {
            if (event.wheelDelta > 0) {
                this.zoomIn();
            } else if (event.wheelDelta < 0) {
                this.zoomOut();
            }
        }

为此:

       zoomScroll(event: WheelEvent) {
           if (event.deltaY < 0) {
               this.zoomIn();
           } else if (event.deltaY > 0) {
               this.zoomOut();
           }
    }

来源: https://github.com/Microsoft/TypeScript/issues/9071

这篇关于如何修复属性"wheelDelta"在类型"WheelEvent"上不存在升级到有角度的7,rxjs6时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 19:36