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

179
Views
¿Cómo registrar el evento onClick después del cambio de estado?

Tengo un evento javascript de una biblioteca externa como esta:

 this.flky.on('staticClick', (e) => { this.setState({mobileZoom: true})

Cuando hago clic en él, una imagen se expande:

 <img onClick={this.state.zoom && () => {this.setState({mobileZoom: false}}} style={...this.state.mobileZoom && {position: 'absolute', top: 0, left: 0, width: 'auto', zIndex: 1070}} />

Esto funciona en el escritorio, pero en el móvil, el evento onClick de la imagen de pantalla completa también se activa, lo que hace que la imagen parpadee y luego desaparezca nuevamente.

Funciona si agrego un retraso:

 this.flky.on('staticClick', (e) => { setTimeout(() => { this.setState({mobileZoom: true}) }, 100) )

pero no tengo idea de cuánto dura el evento de clic en diferentes dispositivos, por lo que esta no es una solución sostenible y una mala práctica. ¿Hay una mejor manera?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar event.stopPropagation() para detener el event burbujeante más

 this.flky.on('staticClick', (e) => { if (event.stopPropagation){ //checking browser support event.stopPropagation(); }else{ window.event.cancelBubble = true; } this.setState({mobileZoom: true}); )

Como ejemplo

 function inside(e){ e.stopPropagation(); alert('you clicked inside'); } function outside(e){ alert('you clicked ouside'); }
 <div onclick="outside(event)"> Outside <div onclick="inside(event)">Inside</div> </div>

over 4 years ago · Santiago Trujillo Report

0

Parece que tienes un error tipográfico en el onClick :

 <img onClick={this.state.mobileZoom && () => {this.setState({mobileZoom: false}}} style={...this.state.mobileZoom && {position: 'absolute', top: 0, left: 0, width: 'auto', zIndex: 1070}} />
over 4 years ago · Santiago Trujillo 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!