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

222
Vistas
How to play a youtube video when I hover on an image in React js?

Is there any ways to play a youtube video when we hover over an image.I checked react-hover-video-player but couldnt play youtube videos.The video must be played in desired size when hovered on image.

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

0

You could try something like this:

  1. Add an event listener (mouseover) to the image you want to trigger the video from
  2. Load the URL of the video into the iframe

YouTube probably requires this to be loaded from a server, and not just opened as an index.html file directly in the browser window.

<!doctype html>
<html class="no-js" lang="en">

<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

<img src="https://via.placeholder.com/150" id="image" alt="Placeholder image" />

<div id="youtube">
    <iframe title="YouTube video player" frameborder="0" allowfullscreen></iframe>
</div>

<script>
    const hoverable = document.querySelector('#image');

    function showVideo() {
        const video = document.querySelector('#youtube iframe');
        video.src = 'https://www.youtube.com/embed/LatorN4P9aA';
        video.style.width = '560px';
        video.style.height = '315px';
        video.allow ='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
        hoverable.removeEventListener('mouseover', showVideo);
    }

    hoverable.addEventListener('mouseover', showVideo);
</script>

</body>

</html>

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