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

110
Visualizações
Touch events not triggered on element edges in iOS Safari

On touch devices the following events are triggered when touching an element:

  • touchstart
  • touchend
  • mouseenter
  • mousedown
  • mouseup
  • click

The mouseenter, mousedown, mouseup and click events are emulated by the touchend event. If you want to disable this emulation of mouse events, preventDefault() can be used.

But if in iOS Safari I touch the edges of an element the following events are triggered:

  • mouseenter
  • mousedown
  • mouseup
  • click

Somehow the touch events are not triggered on the edges and because of this I also can't use preventDefault() to stop the emulation of the mouse events.

The problem occurs on both iPhone as iPad.

I searched Stack Overflow and Google, but I can't find anything about this. No bugs and no solutions. Does anybody know if this is a known bug in Safari?

I created the most basic code to reproduce this error in JSFiddle:

HTML:

<div id="element"></div>
<div id="log"></div>

CSS:

#element {
  height: 100px;
  width: 100px;
  background: yellow;
  margin: 20px;
}

JavaScript:

function handler(event) {
  const log = document.getElementById('log');
  
  log.innerHTML = `${event.type}<br />${log.innerHTML}`;
}

const element = document.getElementById('element');

element.addEventListener('mouseenter', handler);
element.addEventListener('mouseleave', handler);
element.addEventListener('mousedown', handler);
element.addEventListener('mouseup', handler);
element.addEventListener('click', handler);
element.addEventListener('focus', handler);
element.addEventListener('blur', handler);
element.addEventListener('touchstart', handler);
element.addEventListener('touchend', handler);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try attaching the event listener to the outermost element, the html tag.

See more: https://www.tutorialrepublic.com/javascript-tutorial/javascript-event-propagation.php

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