Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Cómo capturar el evento del mouse sobre múltiples divs

Tengo muchos componentes que están uno encima del otro, y necesito agregar un oyente para que cuando el puntero del mouse esté dentro de los límites de estos componentes, cada componente haga algo.

Probé con mouseover, mouseenter, mousemove, etc. pero estos eventos solo funcionan en el componente que está en la parte superior, no en todos. ex html:

 <div class="container"> <app-child></app-child> <app-child></app-child> <app-child></app-child> <app-child></app-child> </div>

ex css:

 .container > * { position: absolute; left: 0; top: 0; width: 100px; height: 100px; border: 1px solid black; }

ex app-child.component.ts

 @Component({ selector: 'app-child', template: '<div></div>' }) ChildComponent { // Here some function that needs to run if mouse pointer is in bound of this element }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

si quieres que los niños hagan algo

padre.componente.html

 <div class="container" (mouseenter)="doSomethingFunction()" (mouseleave)="stopDoSomething()> <app-child [doSomething]="doSomething"></app-child> <app-child [doSomething]="doSomething"></app-child> <app-child [doSomething]="doSomething"></app-child> <app-child [doSomething]="doSomething"></app-child> </div>

padre.componente.ts

 @Component({ selector: 'app-child', template: '<div></div>' }) ParentComponent { doSomething = false; doSomethingFunction(e) { doSomething = true; } stopDoSomething(e) { doSomething = false; } }

child.component.ts

 @Component({ selector: 'app-child', template: '<div></div>' }) ChildComponent { @Input() doSomething: boolean ngOnInit() { if(doSomething) { doSomethingElse(); } else { stopDoingThings(); } } }

si hay que hacerle algo a los niños

padre.componente.html

 <div class="container" (mouseenter)="doSomething($event)"> <app-child></app-child> <app-child></app-child> <app-child></app-child> <app-child></app-child> </div>

padre.componente.ts

 @Component({ selector: 'app-child', template: '<div></div>' }) ParentComponent { doSomething(e) { for(const child in Array.from(e.target.children) { doSomethingElse(child); } } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!