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

190
Views
Angular 8, ¿cómo detectar el div actual "desplazado a"?

Tengo un div con divs internos a los que puedo desplazarme pasando su id a una función. Me pregunto cómo puedo hacer lo contrario: detectar la identificación de div cuando se revela/desplazarse hacia, y así cambiar la clase del botón al que pertenece. Entonces, por ejemplo, si me desplazo a "div medio" (número 5), quiero poder detectarlo y resaltar el botón "medio" - para todos ... desplácese hasta el último div - y luego el botón "último" debería ser resaltado.

ingrese la descripción de la imagen aquí

Ejemplo

 @Component({ selector: 'my-app', template: ` <div class="main-wrapper"> <div class="button-wrapper"> <button *ngFor="let item of buttonsArr" [ngClass]="{'active': item.isActive}" (click)="scrollToElement(item)" class="nav-btn">{{item.key}}</button> </div> <div class="content"> <button (click)="scrollToElement()">Scroll prev</button> <button (click)="scrollToElement()">Scroll next</button> <div class="wrapper"> <li *ngFor="let item of itemList; let i = index" id="elem-{{i}}">{{item}}</li> </div> </div> </div> `, }) class HomeComponent { text = 'foo'; buttonsArr = [{key:'first', value:1},{key:'middle', value:4}, {key:'last', value:11}]; testObject = {fieldFirst:'foo'}; itemList = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', ]; scrollToElement(elemId?) { if(elemId){ document.getElementById("elem-"+elemId.value).scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"}); this.buttonsArr.forEach(i => { i.isActive = false}) elemId.isActive = true; }else{ document.getElementById("elem-7").scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"}); } }

}

about 4 years ago · Juan Pablo Isaza
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!