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

258
Vistas
HTML5 <video> with text overlay executes onMouseOut load() function near the text

I'm having trouble with an HTML5 video. Look it is a video that when you hover in it has to show a semi transparent overlay including text. When the mouse goes out, it has to show again the poster. The poster is an attribute that shows a thumbnail of the video when is not played yet.

In order to show the poster, I have searched other Stack Overflow questions and the workaround is to do: video.load();.

So I have the next piece of code:

HTML:

<div class="video-container" onMouseOver="video.play();showOverlay('#video-overlay');" onMouseOut="video.load();hideOverlay('#video-overlay');">
  <video poster="https://example.com/poster.jpg" src="https://example.com/video.mp4" id="video" width="300" muted="muted" loop title="Example video" />
  <a href="#">
    <div class="overlay" id="video-overlay">
      <h5>Overlay Title</h5>
      <p>Overlay Description</p>
    </div>
  </a>
</div>

CSS:

.video-container {
  position: relative;
}

.overlay {
    background: rgba(0,0,0,0.6);
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: 0.5s ease-in;
    z-index: 999; /* does not work */
}

.overlay > h5 {
    font-size: 30px;
    font-weight: 900;
    text-transform: uppercase;
}

JS:

function showOverlay(selector){
  const overlay = document.querySelector(selector);
  overlay.style.opacity = "1";
}
function hideOverlay(selector){
  const overlay = document.querySelector(selector);
  overlay.style.opacity = "0";
}

WATCH THE DEMO

The problem:

Well, when you hover the video and you are near the text (h5 or p tags) the video loads again. It should not restart, instead, continue as normal.

Tip: I have replaced video.load(); for video.pause(); and everything works fine. But that is not the functionality I want.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

ok, here is the edit:

I think your problem is due to the difference in behavior between mouseover/mouseout events and mouseeenter/mouseleave events.

replacing the events in your code, should give you the desired behavior

<div class="video-container" onMouseEnter="video.play();showOverlay('#video-overlay');" onMouseLeave="video.load();hideOverlay('#video-overlay');">

info and examples on the behavior of these events and differences:

https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event

https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseenter_event

https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseleave_event

about 4 years ago · Juan Pablo Isaza 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