This is a classic. You have parent and child elements. The child element is absolutely positioned, and you want the user to view its contents. However, when you reach the bottom of the child, the parent (which also has the ability to have scrollbars) starts to scroll. This is undesirable. The main behavior I want to reproduce is the comment section in The New York Times. For example :

The body is allowed to scroll down, but when you are at the bottom of the comment section, scrolling down does nothing. I think the main difference in this case is that I want the user to scroll down when the cursor is over the body element. Other approaches require adding a class to the body to prevent any scroll event in the body. I thought I could do this with a bit of Javascript in Angular 2, but this is my unsuccessful attempt:

I have a custom directive in my child component:
<child-element scroller class="child"></child-element>
and this directive should stop distributing the scroll event to the body element:
import {Component} from 'angular2/core' import {Directive, ElementRef, Renderer} from 'angular2/core'; @Directive({ selector: '[scroller]', }) export class ScrollerDirective { constructor(private elRef: ElementRef, private renderer: Renderer) { renderer.listen(elRef.nativeElement, 'scroll', (event) => { console.log('event!'); event.stopPropagation(); event.preventDefault(); }) } }
It actually listens for the event, but does not stop the distribution.
Demo : Scroll down the list and when you reach the bottom, its parent starts scrolling down. This is problem.
If you have a different approach to achieving this, let me know.
thanks
UPDATE . Based on Günter Zöchbauer's answer, I try to prevent the wheel event when the user reaches the bottom. This is basically what I have in this updated demo :
renderer.listen(elRef.nativeElement, 'wheel', (e) => { console.log('event', e); console.log('scrollTop', elRef.nativeElement.scrollTop); console.log('lastScrollTop', lastScrollTop); if (elRef.nativeElement.scrollTop == lastScrollTop && e.deltaY > 0) { e = e || window.event; if (e.preventDefault) e.preventDefault(); e.returnValue = false; } else if (elRef.nativeElement.scrollTop == 0) { lastScrollTop = -1; } else { lastScrollTop = elRef.nativeElement.scrollTop; } }, false)
However, the logic is ugly and does not work perfectly. For example, when the user reaches the bottom, scrolls a little and scrolls again, the parent component moves a bit. Does anyone know how to deal with this? Is (much) better to implement?
UPDATE 2 :
This is much better, but it's already late, so tomorrow I will check again.