简体   繁体   English

如何在 rxjs 中冒泡滚动事件

[英]how in rxjs bubble a scroll event

with vanilla js, I can write something like this to catch any scroll on any element (pay attention to true as the last argument)使用 vanilla js,我可以写这样的东西来捕捉任何元素上的任何滚动(注意true作为最后一个参数)

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但是使用 rxjs 我不能冒泡(或者我不知道怎么做),这样的东西不起作用

fromEvent(window, 'scroll').subscribe(console.log);

how to register an event in rxjs that support bubbling?如何在支持冒泡的 rxjs 中注册事件?

You can pass options to fromEvent (see Examples) as well:您也可以将选项传递给fromEvent (参见示例):

fromEvent(window, 'scroll', { capture: true }).subscribe(console.log);

// or

fromEvent(window, 'scroll', true).subscribe(console.log);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM