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

213
Visualizações
Prevent default on screen, but allow buttons to be pressed

I'm building a website in js/html/css. To play part of my game the user needs to press and hold the screen. This will default to highlighting the play area, so on click or touch events I want to use an event.preventdefault(). The problem then is that the user can not click on other buttons on the page.

Is there a way to both prevent default when clicking and holding, but also allow buttons to work as normal?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I think something like this might work. Basically using a boolean variable to detect if an specific button has been clicked and then add a conditional statement to the e.preventDefault() so when the button is clicked is not affected by the e.preventDefault()

let isClicked = false

document.getElementById('myBtn').addEventListener('click', () => {
   isClicked = true
   
   setTimeOut(() => {
      isClicked = false 
   }, 100)    
})

function myPreventDefaultFunction(e){
   if(isClicked){
     // do something 
   } 
   else{
     e.preventDefault() 
   }
}

about 4 years ago · Santiago Gelvez 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