How can I detect horizontally scrolling on an element
I have a div in a containing div that scrolls left to right.
I want to detect the when the div is scrolling.
I can use this to detect the window scrolling, but how do I detect one element scrolling
@HostListener("window:scroll", []) onWindowScroll() {
console.log('scrolling');
const verticalOffset = window.pageYOffset
|| document.documentElement.scrollTop
|| document.body.scrollTop || 0;
}
You can handle the scroll event of the container div:
<div class="container" (scroll)="onScroll($event)">
<div class="content">
Some content
</div>
</div>
onScroll(event: Event) {
console.log(event);
...
}
See this stackblitz for a demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With