N
N
Nikita Shchypylov2016-08-02 11:22:24
YouTube
Nikita Shchypylov, 2016-08-02 11:22:24

How to add a preview to a video on YouTube, but so that it does not load the video itself?

Hello everyone
There are several YouTube videos on the page, but if you add them all at once, the page takes a terribly long time to load. You need to add a video preview, and if you click on it, the video will be loaded into the container. Now I have this implementation:
<a class="img_slide video_0" href="#"></a>

function addVideoYoutube() {
    var element = document.getElementsByClassName('video_0')[0];
    var el2 = document.getElementById('ytplayer');
    element.addEventListener('click', function (e) {
        e.preventDefault();
        el2.innerHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/99-n42Xb6NQ?autoplay=1" frameborder="0" allowfullscreen></iframe>'
    });

}

But on the tag and now it's just a picture, but you need a preview, like here
joxi.ru/p27RGOBCpaznm7
Thank you for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2016-08-02
@Denormalization

Take the video ID and pull the preview from YouTube stackoverflow.com/questions/2068344/how-do-i-get-a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question