Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
jQuery continuous mousedown

I have the following code snippets

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

I can capture the mousedown event successfully.

I am trying to do the following:

  1. Capture the first mousedown event
  2. I want to detect if the user is still holding the mouse down so I can do something else.
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Something like

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 Denunciar

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 //
}

You can also put a clearInterval on the mouseleave event.

over 4 years ago · Santiago Trujillo Denunciar

0

You'd implement some recursion!

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda