2016-12-17 33 views
0

我試圖讓視頻打開並使用.click函數使用jQuery。我已經在不同的網站上看到了這一點,網站上有一個播放按鈕,點擊時,網站的其他部分變暗,視頻播放器打開,視頻播放。我想在我的網站上執行此操作,但我不知道如何繼續。任何幫助將真誠的讚賞。謝謝!如何使用jQuery打開視頻並在.click上播放?

<a class="playBtn" href="#"><i class="fa fa-play-circel fa-3x" aira-hidden="true"></i></a> <!--Is the button I want to use to activate the video.--> 
<script> 
    $(document).ready(function() { 
      $(".playBtn").click(function(){ 

      }); 
     }); 
    </script> 
+0

哪裏是你的代碼? –

+0

我添加了一些我有,但我不知道如何從那裏繼續下去,不好用jquery –

+0

也粘貼視頻標籤'

回答

0

這裏有你所需要的簡化演示:

$(document).ready(function($) { 
 
    $('#playButton').click(function() { 
 
     $('#myVideo')[0].paused ? $('#myVideo')[0].play() : $('#myVideo')[0].pause(); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<video id="myVideo" width="320" height="240" controls> 
 
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> 
 
Your browser does not support the video tag. 
 
</video> 
 
<br> 
 
<button id="playButton">Play/Pause</button>