【发布时间】:2020-12-16 09:12:43
【问题描述】:
当条件为真时,我想跳过/忽略 订阅 fromEvent() observable:
当this.currentPosition === this.vc.getScrollPosition()[1] 我不想订阅 observable 因为它直接滚动到下一个项目,我的目标是等待用户交互滚动到我界面上的下一个项目..
fromEvent(window, 'scroll').pipe(
distinctUntilChanged(),
debounceTime(1000)
)
.subscribe(
(event) => {
const current = this.positions.find(e => e.name === this.currentSectionName);
const indexOfCurrent = this.positions.indexOf(current);
if (indexOfCurrent + 1 === this.positions.length) {
// stay in the same position if it's the last item
this.vc.scrollToPosition([0, current.position]);
this.currentPosition = current.position;
} else {
// move to next position if it's not the last item
const next = this.positions[indexOfCurrent + 1];
this.vc.scrollToPosition([0, next.position]);
this.currentPosition = next.position;
}
}
);
【问题讨论】:
标签: javascript angular typescript rxjs