通过this线程,我可以设置我的应用程序,这样当一个人滚动时它就会导航。我只有一个问题,任何地方都找不到它的信息!如何设置滚动事件的“敏感度”?我的问题是,通常即使有最轻微的scroll,它也会导航多条路线,而不仅仅是给我下一条路线。正如你所看到的GIFF附件,这是与我的触摸板非常轻的移动,它走得太快了,从大约到巡视到画廊到所有其他导航点!有没有办法调节速度,延迟,灵敏度之类的?
事件监听器被放置在所有的components上,如下所示!这是来自我的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'])
}

发布于 2019-11-28 01:47:19
应尝试限制或解除scroll事件的抖动。有n种方法可以实现scroll事件的去保证器。
i)使用普通的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 event
理想情况下,这将通过在导航中延迟来延迟滚动事件的发生。
发布于 2019-11-28 01:41:26
由于您是在scroll上导航,这意味着在app.component.ts或任何其他更高级别的组件中,您已经启用了侦听器。
你可以把它放在像这样的地方
...
// we'll use this to ignore scrolling event
navigating = false;
constructor(
...
private readonly router: Router
) {
this.router.events.subscribe(e => {
if (e instanceof NavigationStart) {
this.navigating = true;
} else if (e instanceof NavigationEnd) {
this.navigating = false;
}
});
}如果它是一个简单的回调函数,则在处理程序中
if (this.navigating) {
return;
}如果您使用的是RxJ的fromEvent,则为filter
source$.pipe(filter(e => !this.navigating))
这是一个example
https://stackoverflow.com/questions/59074727
复制相似问题