Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use mouse enter and mouse exit or hover

I want to show and hide one popup/tooltip on mouse hover.

popups are multiple as below

 <div class="hotspot_info pointer" style="    top: {{towerPoint.posY}}%;    left: {{towerPoint.posX}}%;" *ngFor="#towerPoint of visualisation.towerPoints">
            <div class="tower-details"  style="    position: absolute;    top: -90px;    left: -84%;">
                <div class="popover top" style="display: block;">
                    <div class="arrow" style="left: 50%;"></div>
                    <h3 class="popover-title">{{towerPoint.tower.name}}</h3>
                    <div class="popover-content">Tower Name</div>
                </div>
            </div>

on hover to ".tower-details" I want to show ".popover" and on mouseexit from hide ".popover"

like image 713
Arun Tyagi Avatar asked Apr 11 '16 11:04

Arun Tyagi


People also ask

What is the use of mouse hover?

Hovering is a fundamental digital action that involves placing the mouse cursor on the target link or button. Users mainly use the mouse hover action to access sub-menu items.

What is mouse exit?

The mouseleave event is fired at an Element when the cursor of a pointing device (usually a mouse) is moved out of it. mouseleave and mouseout are similar but differ in that mouseleave does not bubble and mouseout does.

What is the difference between mouse enter and mouse over?

This example demonstrates the difference between mousemove, mouseenter and mouseover. The mouseover event triggers when the mouse pointer enters the div element, and its child elements. The mouseenter event is only triggered when the mouse pointer enters the div element.

Is mouse over same as hover?

The hover() function is more high level - it's built to call functions to handle both a mouseenter event and a mouseleave event. It's very convenient for a UI element that has a hover and normal state (e.g. a button.) The mouseover() function specifically binds to the mouseover event.


1 Answers

To listen on a single tag you can use:

@Component({
  selector: 'my-component',
  directives: [PopUp],
  template: `
<div (mouseover)="mouseover=true" (mouseout)="mouseover=false">xxx</div>
<pop-up *ngIf="mouseover">some content</pop-up>
`
})
class MyComponent {
  mouseover:boolean;
}

See also What is the difference between the mouseover and mouseenter events?

For a component to listen on itself on the mouse events you can use:

@Component({
  selector: 'my-component'
  directives: [PopUp],
  template: `
    xxx
    <pop-up *ngIf="mouseover">some content</pop-up>`
})
class MyComponent {
  mouseover:boolean;

  @HostListener('mouseover')
  onMouseOver() {
    this.mouseover = true;
  }

  @HostListener('mouseout')
  onMouseOut() {
    this.mouseover = false;
  }
}
like image 168
Günter Zöchbauer Avatar answered Nov 03 '22 00:11

Günter Zöchbauer