admin管理员组文章数量:1391960
with vanilla js, I can write something like this to catch any scroll on any element (pay attention to true as the last argument)
document.addEventListener('scroll', function(e) {
console.log(e);
}, true);
but with rxjs I can't do the bubbling (or I don't know how) and something like this doesn't work
fromEvent(window, 'scroll').subscribe(console.log);
how to register an event in rxjs that support bubbling?
with vanilla js, I can write something like this to catch any scroll on any element (pay attention to true as the last argument)
document.addEventListener('scroll', function(e) {
console.log(e);
}, true);
but with rxjs I can't do the bubbling (or I don't know how) and something like this doesn't work
fromEvent(window, 'scroll').subscribe(console.log);
how to register an event in rxjs that support bubbling?
Share Improve this question edited Dec 16, 2020 at 14:07 Mohammad Hossein Amri asked Dec 16, 2020 at 11:02 Mohammad Hossein AmriMohammad Hossein Amri 2,0452 gold badges30 silver badges50 bronze badges2 Answers
Reset to default 7You can pass options to fromEvent
(see Examples) as well:
fromEvent(window, 'scroll', { capture: true }).subscribe(console.log);
// or
fromEvent(window, 'scroll', true).subscribe(console.log);
Just in case it might be helpful for someone. To target scroll of specific element:
const el = document.getElementById('element-id-with-scroll') as HTMLElement;
fromEvent(el, 'scroll')
.pipe(
debounceTime(300)
)
.subscribe(res => console.log(res))
本文标签: javascripthow in rxjs bubble a scroll eventStack Overflow
版权声明:本文标题:javascript - how in rxjs bubble a scroll event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744694096a2620171.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论