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

120
Views
jQuery mousedown continuo

Tengo los siguientes fragmentos de código

 $(document).mousedown(function(event) { doSomething(); }

Puedo capturar el evento mousedown con éxito.

Estoy tratando de hacer lo siguiente:

  1. Capture el primer evento mousedown
  2. Quiero detectar si el usuario aún mantiene presionado el mouse para poder hacer otra cosa.
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Algo como

 var mouseStillDown = false; $(document).mousedown(function(event) { mouseStillDown = true; doSomething(); }); function doSomething() { if (!mouseStillDown) { return; } // we could have come back from // SetInterval and the mouse is no longer down // do something if (mouseStillDown) { setInterval("doSomething", 100); } } $(document).mouseup(function(event) { mouseStillDown = false; });
over 4 years ago · Santiago Trujillo Report

0

var int00; // declared here to make it visible to clearInterval. $('#trigger').mousedown(function(){ int00 = setInterval(function() { repeatingfunction(); }, 50); }).mouseup(function() { clearInterval(int00); }); function repeatingfunction() { // This will repeat // }

También puede poner un clearInterval en el evento mouseleave .

over 4 years ago · Santiago Trujillo Report

0

¡Implementarías algo de recursividad!

 var mouseisdown = false; $(document).mousedown(function(event) { mouseisdown = true; doSomething(); }).mouseup(function(event) { mouseisdown = false; }); function doSomething(){ //Code goes here if (mouseisdown) doSomething(); }
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!