html - 如何获取滚动事件?

标签 html css angular typescript scrollbar

我需要从带有溢出的 div 获取滚动事件:在我的 Angular 2 应用程序中滚动。

好像onscroll event不适用于 Angular 2。

我怎样才能做到这一点?

最佳答案

// @HostListener('scroll', ['$event']) // for scroll events of the current element
@HostListener('window:scroll', ['$event']) // for window scroll events
onScroll(event) {
  ...
}

<div (scroll)="onScroll($event)"></div>

关于html - 如何获取滚动事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41304968/

相关文章:

html - 从 googleusercontent.com 加载的图像上的 HTTP 403

javascript - 为什么我的 Bootstrap Carousel 无法缩放?

javascript - 获取 HTML 输入中的插入符号位置?

c# - MVC - 如何根据条件在下拉列表中添加 css 属性

jquery - 不在 jQuery 中循环

Angular 6 : ERROR Error: Cannot find control with unspecified name attribute with angular material and reactive forms

c# - 如何在 Outlook 中显示系统发送的电子邮件中的背景图像?

html - 两个 div 彼此相邻,全宽

html - 具有重叠 DIV 的 webkit-filter 灰度

css - 无法在 Angular 4 中添加 Sass