Is there a method to continuously execute a function while the cursor hovers over a specific DOM element? I need to trigger a scroll action whenever the user hovers over an arrow, with an optional timeout feature. This requirement must be met without utilizing jQuery!
Check out my current code snippet:
public onHoverDown() {
this.tabList.nativeElement.scrollBy(0, 10);
const element = this.tabList.nativeElement;
if(element.offsetHeight + element.scrollTop >= element.scrollHeight) {
console.log('Reached Bottom Limit');
}
}
public onHoverUp() {
this.tabList.nativeElement.scrollBy(0, -10);
const element = this.tabList.nativeElement;
if(element.scrollTop === 0) {
console.log('Reached Top Limit');
}
}
Here's the corresponding HTML:
<div class="list-arrow-up" (mouseover)="onHoverUp()">▲</div>
<ul #tabList>
<li><!-- Multiple list items --></span></li>
</ul>
<div class="list-arrow-down" (mouseover)="onHoverDown()">▼</div>