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

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

    To start video

    var videoURL = $('#playerID').prop('src');
    videoURL += "&autoplay=1";
    $('#playerID').prop('src',videoURL);
    

    To stop video

    var videoURL = $('#playerID').prop('src');
    videoURL = videoURL.replace("&autoplay=1", "");
    $('#playerID').prop('src','');
    $('#playerID').prop('src',videoURL);
    

    You may want to replace "&autoplay=1" with "?autoplay=1" incase there are no additional parameters

    works for both vimeo and youtube on FF & Chrome

提交回复
热议问题