简体   繁体   English

Safari 上的生涩 translate3d animation

[英]Jerky translate3d animation on Safari

I'm getting a strange problem on safari (on both on macOS and iOS).我在 safari 上遇到了一个奇怪的问题(在 macOS 和 iOS 上)。 I'm trying to do a bottom drawer in a ionic app (with Angular) and while everything is very smooth on chrome, the drag animation is very jerky on safari and have a lot of "lags" while following the touch event.我正在尝试在 ionic 应用程序(使用 Angular)中做一个底部抽屉,虽然 chrome 上的一切都非常流畅,但拖动 animation 在 safari 上非常生涩,并且在触摸事件之后有很多“滞后”。

Here is my code:这是我的代码:

private init() {
    const hammer = new Hammer(this.element.nativeElement, { touchAction: 'pan-x' });

    hammer.get('pan').set({ enable: true, direction: Hammer.DIRECTION_VERTICAL });

    hammer.on('panstart', (ev) => this.onPanStart(ev));
    hammer.on('panup', (ev) => this.onPan(ev, PanDirection.Up));
    hammer.on('pandown', (ev) => this.onPan(ev, PanDirection.Down));
  }

private onPanStart(ev: HammerInput) {
const matrix = getComputedStyle(this.element.nativeElement).transform;
        const y = fromString(matrix).f;

    this.startingTop = y;
  }

private onPan(ev: HammerInput, direction: PanDirection){
    this.direction = direction;
    const position = clamp(ev.deltaY + this.startingTop, this.range.top, this.range.bottom);

    if(this.bounce && ev.isFinal) {
      return;
    }

    this.domController.write(() => this.renderer.setStyle(this.element.nativeElement, 'transform', `translate3d(0, ${ position }px, 0)`));
  }

After some debugging, it seems that the problem come from the translate3d update, so I've tried to run this very simple function to see how it will render and the problem appear is there again:经过一些调试,问题似乎来自 translate3d 更新,所以我尝试运行这个非常简单的 function 来查看它会如何渲染,问题又出现了:

setInterval(() => {
  const y = this.element.nativeElement.getBoundingClientRect().top;

  this.domController.write(() => this.renderer.setStyle(this.element.nativeElement, 'transform', `translate3d(0, ${ y - 1 }px, 0)`));
}, 1);

Also here is the CSS of the translating element:这里还有翻译元件的 CSS:

width: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 100;
transform: translate3d(0, 0, 0);
will-change: transform;

Here is videos illustrating the problem (both run on the same computer):这是说明问题的视频(都在同一台计算机上运行):

Chrome: https://streamable.com/acj93镀铬: https://streamable.com/acj93

Safari: https://streamable.com/b4887 Safari: https://streamable.com/b4887

What's wrong here?这里有什么问题?

You can try to force the hardware acceleration on the browser to make it look smoother and flicker less.您可以尝试在浏览器上强制硬件加速,使其看起来更流畅,闪烁更少。

 width: 100%; position: absolute; top: 0; left: 0; z-index: 100; transform: translate3d(0, 0, 0); /* Add this */ -webkit-transform: translate3d(0, 0, 0,); -webkit-backface-visibility: hidden; -webkit-perspective: 1000;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM