Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!