Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Menu's mouseover event triggers after hovering over inner element's

I have a menu that show’s only when user hover’s on element. And that menu stay’s visible only when user hover’s on menu. if user mouseout of menu it will hide. The problem is that there are elements in the menu and when you hover over them, the mouseout menu event fires.

<a (mouseover)="showMenu()" (mouseout)="hideMenu()"</a>

<menu *ngIf="isHoverable" (mouseover)="show(true)" (mouseout)="show(false)"></menu>

To open menu with a delay, the following methods were written

isHoverable: boolean = false;
timer: any;

show(show: boolean): void {
    clearTimeout(this.timer);
    this.isHoverable = show;
}

showMenu(): void {
    this.timer = setTimeout(() => {this.show(true)}, 500);
}

hideMenu(): void {
    clearTimeout(this.timer);
    this.timer = setTimeout(() => {this.show(false)}, 500);
}

I want to open menu on hovering element and close only when the cursor leaves the menu. Not closing the menu when hovering over it elements

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try mouseenter and mouseleave – that might suit your purposes

There’s a good example of the two approaches (mouseover vs mouseenter) on mdn

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading