如何设置Angular 8车轮事件的灵敏度? [英] How to set the sensitivity of Angular 8 wheel event?

查看:143
本文介绍了如何设置Angular 8车轮事件的灵敏度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过这个线程,我当时能够设置我的应用程序,以便在滚动时进行导航.我只有一个问题,找不到任何地方的信息!如何设置滚动事件的敏感度"?我的问题是,即使使用最小的scroll,它也会导航多条路线,而不仅仅是给我下一条路线.在随附的GIFF中可以看到,触控板的移动非常轻巧,从关于"到游览"到图库"到所有其他导航点的移动速度都太快了!有什么办法可以调节速度,延迟,灵敏度吗?

Going by this thread, I was able to set my app up so that it navigates when one scrolls. I have just one issue, information for which have not been able to find anywhere! How do I set the "sensitivity" of the scroll event? My issue is that often even with the slightest scroll, it navigates multiple routes rather than just giving me the next one. As you can see in the GIFF attached, this is with very light movement of my trackpad and it goes too fast from About to Tour to Gallery to all other navigation points! Is there a way to regulate the speed, delay, sensitivity anything?

事件侦听器放置在所有components上,如下所示!这是我的tours.component.ts

The event listener is placed on all the components like below! This is from my tours.component.ts

  @HostListener('wheel', ['$event'])
  onWheelScroll(evento: WheelEvent) {
    // Scroll down go to gallery
    if (evento.deltaY > 0) {
      this.router.navigate(['gallery'])
      // Scroll up go to about
    } else {
      this.router.navigate(['about'])
    }

推荐答案

应尝试限制或取消滚动事件.有n种方法可以实现滚动事件的去抖动器.

Should try throttling or debouncing the scroll event. There are n number of ways to implement debouncer for scroll event.

i)使用香草javascript方法, https://davidwalsh.name/javascript-debounce-function

i) Using vanilla javascript method, https://davidwalsh.name/javascript-debounce-function

ii)使用RxJs运算符, https://www.codementor.io/abolaji_dev/throttling-and-debounce-with-rxjs-observable-cjcgdii1d

ii) Using RxJs operators, https://www.codementor.io/abolaji_dev/throttling-and-debounce-with-rxjs-observable-cjcgdii1d

iii)使用Angular方式,消除@HostListener事件

iii) Using Angular way, Debounce @HostListener event

理想情况下,这将通过延迟导航来延迟滚动事件的出现.

This would ideally delay the scrolling event occurrences there by delay in navigation.

这篇关于如何设置Angular 8车轮事件的灵敏度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆