Youtube Video Autoplay in popup

前端 未结 4 1394
一向
一向 2021-02-03 11:08

I\'ve made a popup and placed a youtube video in it. I set video to autoplay. But the problem is video plays when i open the page. It is auto play in global and i want it to aut

4条回答
  •  爱一瞬间的悲伤
    2021-02-03 11:48

    I think you want something like that :

    LIVE EXAMPLE

    Basically i use the API Javascript to add actions play and pause to the video.

    And i use default function of Foundation to add an event when to the player.

    HTML

     Click Me For A Modal
    
      

    Awesome

    ×

    JS

    var tag = document.createElement('script');
    
    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    
    // 3. This function creates an