如何获得播放按钮以触发视频播放动作?

时间:2018-10-03 05:37:18

标签: jquery html5-video vimeo

在此页面上,我有两个div,div-1与另一个div-2 http://55-corinthian-drive.webflow.io/home-video-wip

重叠

Div-1包含播放按钮(以及大图像和文本),单击播放按钮div-1会关闭显示div-2的内容,该div-2包含Vimeo视频。我希望视频在单击按钮后就可以开始播放,但是无法正常工作。下面是我删除div-1的脚本,它工作正常。我已经看过这个想法https://jsfiddle.net/ELHCm/,但无法正常工作,正在尝试$(“#id”)。vimeo(“ play”);现在。

 <!-- triggering div -->
<div class="video-trigger-wrap">
    <h1 class="header">text to remove on click</h1>   
    <div class="video-trigger"></div>  
</div>

<!-- video -->
<div class="div-block-23 position-vid">
    <div id="w-node-df98048f0945" class="video-4 w-video w-embed">       
        <iframe id="g-vid" src="video-address"  frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
    </div>
</div>


<script>
$(document).ready(function(){
    $(".video-trigger").click(function(){
        $(".video-trigger-wrap").toggle();
        $("#player").vimeo("play");

    });
});
</script> 


Also tried the following, as suggested by Charan below, but has not worked.
    <script>
      $(document).ready(function(){
          $(".video-trigger").click(function(e){
             e.preventDefault();
             $(".video-trigger-wrap").toggle();
             $("#g-vid").vimeo("play");       
       }); 

  });

 </script>

1 个答案:

答案 0 :(得分:0)

尝试使用“点击”事件而不是点击事件,因为您正在动态附加iframe

$('a').on('click',function(e) {
    e.preventDefault();
  $('#video_container').html('<iframe src="https://player.vimeo.com/video/12345?title=1&amp;byline=1&amp;portrait=1&amp;autoplay=true" width="643" height="360" frameborder="0"></iframe>');

})