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

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

问题描述

通过

解决方案

应该尝试限制或消除滚动事件.有多种方法可以实现滚动事件的去抖动.

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

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

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

理想情况下,这会因导航延迟而延迟滚动事件的发生.

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?

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'])
    }

解决方案

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

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

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

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天全站免登陆