How to embed YouTube video in a webpage with a custom play-button, original poster at the best resolution and responsive container, keeping aspect ratio
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

15 rindas
843B

  1. (function (document, window) {
  2. document.addEventListener("DOMContentLoaded", function (event) {
  3. const videos = document.querySelectorAll('.youtube-video .youtube-video__play-icon')
  4. videos.forEach(function (video) {
  5. video.addEventListener("click", function (e) {
  6. const link = e.target.dataset.link || null;
  7. const parent = e.target.closest('.youtube-video__wrapper');
  8. if (link && parent) {
  9. parent.classList.add('loading');
  10. parent.innerHTML = '<iframe class="youtube-video__iframe" src="' + link + '?autoplay=1" frameborder="0" allowfullscreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"></iframe>';
  11. }
  12. });
  13. })
  14. });
  15. }(document, window))