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

前端 未结 7 1325
一整个雨季
一整个雨季 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:46

    You can do this simply like this

    $('#image_id').click(function() {
      $("#some_id iframe").attr('src', $("#some_id iframe", parent).attr('src') + '?autoplay=1'); 
    });
    

    where image_id is your image id you are clicking and some_id is id of div in which iframe is also you can use iframe id directly.

提交回复
热议问题