Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda