MurhafSousli / ngx-scrollbar

Custom overlay-scrollbars with native scrolling mechanism
https://ngx-scrollbar.netlify.app/
MIT License
618 stars 99 forks source link

Apply class while scrollbar is hovered #513

Closed Ash66hub closed 1 year ago

Ash66hub commented 1 year ago

What are you trying to do?

Trying to apply a set of style properties while the scrollbar is hovered (mouseenter)

What troubleshooting steps have you tried?

renderer: Renderer2;
const scrollbarClass = this.elementRef.nativeElement.querySelector('scrollbar');
        if (scrollbarClass) {
            this.renderer.listen(scrollbarClass, 'mouseenter', () => {
                console.log('Mouse entered scrollbar!');
                this.isScrollActive = true;
            });
        }

and using ngClass to apply the css class (using less css)

[ngClass]="{
       'scroll-active': isScrollActive
}"

Environment

MurhafSousli commented 1 year ago

At the moment there is no output or stream to notify you when it is hovered, but you can check if it is hovered through a reference to the scrollbar component and ngAfterViewChecked

@ViewChild(NgScrollbar): scrollbar: NgScrollbar;

ngAfterViewChecked() {
  console.log(this.scrollbar.state.horizontalHovered, this.scrollbar.state.verticalHovered);
}

https://stackblitz.com/edit/ngx-scrollbar-edvd7l?file=src%2Fapp%2Fhome%2Fhome.component.ts

Ash66hub commented 1 year ago

Works, thank you very much!!