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

113
Visualizações
Avoid hiding a div when selecting text with a wide swipe

I have a div hided that shows and hide cliking on a buttom (toogle). This div also hides whatever you click anywhere in the document. And finally I also have an stopPropagation click function event on the div so it won't hide when you click on it. All these is working as expected

The input inside the div is a search field that shows results on real time while users are writting and often the users select whatever text they are writting to edit or delete it.

My problem is that when the users are selecting the text and swipe out of the field (while pressing the mouse buttom) the div will automatically hide.

How could I prevent this?

I hope I have explained myself well enough, this may be quiete a confused question.

This is a working example. Just writte anything inside and select it:

$('.input').click(function(e) {
  e.stopPropagation();
})

$('.button').click(function(e) {
  $('.input').slideToggle('fast');
  e.stopPropagation();
})
$(document).on("click", function() { 
  $('.input').slideUp('fast');
});
html {margin-left:100px;}
.button {
  height:50px;
  width:50px;
  background-color:red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="button">
</div>
<div id="divBuscar" class="input" style="display: none;">
  <input type="text" id="txtBuscar" name="txtBus" placeholder="Buscar productos, promociones, novedades...">
  <a id="btnBuscar"></a>
</div>

Ty.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm ashamed I didn't thought about mousedown property.

it works just changing the script like this:

$('.input').mousedown(function(e) {
  e.stopPropagation();
})

$('.button').mousedown(function(e) {
  $('.input').slideToggle('fast');
  e.stopPropagation();
})
$(document).on("mousedown", function() { 
  $('.input').slideUp('fast');
});
about 4 years ago · Juan Pablo Isaza 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