Answer the question
In order to leave comments, you need to log in
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>'
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question