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

105
Views
Necesidad de deshabilitar el clic prolongado en el elemento de la imagen

Tengo el siguiente código en este StackBlitz:

https://stackblitz.com/edit/react-vmstl9

 import React from 'react'; import './style.css'; export default function App() { return ( <div> <h1>Try on Google Chrome Desktop</h1> <p>Open the console log to see how the event gets triggered.</p> <p>The event should not get triggered if there is a long click.</p> <img src="https://via.placeholder.com/200.png/09f/fff" onClick={() => { console.log('You clicked me!'); }} /> </div> ); }

Necesito que el evento de clic se active solo si ocurre un clic normal.

Actualmente, si hago clic en la imagen y mantengo el clic durante 2 segundos, el evento aún se activa. Necesito prevenir eso.

¿Alguna idea sobre cómo lograr eso?

¡Gracias!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Encontré este artículo sobre Stack Overflow encontrado aquí

 const myComponent = () => { let clickHoldTimer = null; const handleMouseDown = () => { clickHoldTimer = setTimeout(() => { //Action to be performed after holding down mouse }, 1000); //Change 1000 to number of milliseconds required for mouse hold } const handleMouseUp = () => { clearTimeout(clickHoldTimer); } return ( <div onMouseDown={handleMouseDown} onMouseUp={handleMouseUp} /> ) }
about 4 years ago · Juan Pablo Isaza Report

0

puedes hacer estos trucos obteniendo el tiempo del titular

https://stackblitz.com/edit/react-d1txdm

 export default function App() { let holdTimer; return ( <div> <h1>Try on Google Chrome Desktop</h1> <p>Open the console log to see how the event gets triggered.</p> <p>The event should not get triggered if there is a long click.</p> <img src="https://via.placeholder.com/200.png/09f/fff" onClick={(e) => { if (holdTimer > 1000) return; else console.log('normal click'); }} onMouseDown={() => { holdTimer = new Date().getTime(); }} onMouseUp={() => { let endHolder = new Date().getTime(); holdTimer = endHolder - holdTimer; }} /> </div> );
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!