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

224
Visualizações
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 Respostas
Responde à pergunta

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 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