start/play embedded (iframe) youtube-video on click of an image

前端 未结 7 1311
一整个雨季
一整个雨季 2020-12-07 22:20

I\'m trying to start playing an embedded youtube video by clicking an image. The idea is to have an image on top of a video, and when the image is clicked it fades out and s

7条回答
  •  隐瞒了意图╮
    2020-12-07 22:47

    The quick and dirty way is to simply swap out the iframe with one that has autoplay=1 set using jQuery.

    THE HTML

    Placeholder:


    Autoplay link:

    Watch the video


    THE JQUERY

    The onClick catcher that calls the function

    jQuery('a.introVid').click(function(){
      autoPlayVideo('VIDEO_ID_HERE','450','283');
    });
    

    The function

    /*--------------------------------
      Swap video with autoplay video
    ---------------------------------*/
    
    function autoPlayVideo(vcode, width, height){
      "use strict";
      $("#videoContainer").html('');
    }
    

提交回复
热议问题