I am searching for a way to retrieve the id of the section element when it reaches the top. A similar task has been accomplished using jQuery on Stack Overflow, but I am looking to achieve the same with Angular. I have tried a similar approach but without any success.
/*let content = document.getElementsByClassName('scrollable');
this.listener = this.renderer2.listen('window', 'scroll', (e) => {
let elementPos = el.getBoundingClientRect().top + window.pageYOffset;
var el = Array.prototype.forEach.call(content, (el)=>{
// console.log(el.id, el.getBoundingClientRect().bottom, parseInt(el.clientHeight))
if(el.getBoundingClientRect().bottom >= parseInt(el.clientHeight)) {
console.log({el})
}
})
*/
section {background: #ccc; height: 100vh;};
section:nth-child(odd) {background: red}
<section class="scrollable" id="scroll1"> Scroll1 </section>
<section class="scrollable" id="scroll2"> Scroll2 </section>
<section class="scrollable" id="scroll3"> Scroll3 </section>
<section class="scrollable" id="scroll4"> Scroll4 </section>
<section class="scrollable" id="scroll5"> Scroll5 </section>