2017-08-20 139 views
0

如何在ajax之後停止視頻?

<head> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
</head> 
 

 
    <section id="top" class="clearfix"> 
 
    <div class="wrapper"> 
 
     <div class="ml-title" style="margin-bottom: 2em"> 
 
      <span class="pull-left top">Watch</span> 
 
      <ul role="tablist" class="nav nav-tabs"> 
 
       <li class="active"><a data-toggle="tab" role="tab" href="#video_1" aria-expanded="false">Video 1</a></li> 
 
       <li> 
 
        <li><a data-toggle="tab" role="tab" href="#video_2" aria-expanded="false">Video 2</a></li> 
 
        <li><a data-toggle="tab" role="tab" href="#video_3" aria-expanded="false">Video 3</a></li> 
 
      </ul> 
 
     </div> 
 
     <div class="tab-content"> 
 
      <div id="video_1" class="rows tab-pane in fade active"> 
 
       <div class="post"> 
 
        <iframe width="560" height="315" src="https://www.youtube.com/embed/kJQP7kiw5Fk" frameborder="0" allowfullscreen></iframe> 
 
       </div> 
 
      </div> 
 
      <div id="video_2" class="rows tab-pane in fade"> 
 
       <div class="post"> 
 
        <<iframe width="560" height="315" src="https://www.youtube.com/embed/JGwWNGJdvx8" frameborder="0" allowfullscreen></iframe> 
 
       </div> 
 
      </div> 
 
      <div id="video_3" class="rows tab-pane in fade"> 
 
       <div class="post"> 
 
        <iframe width="560" height="315" src="https://www.youtube.com/embed/papuvlVeZg8" frameborder="0" allowfullscreen></iframe> 
 
       </div> 
 
      </div> 
 
     </div> 
 
    </div> 
 
</section>

這裏我用引導阿賈克斯。 我在視頻之間切換,然後播放。在視頻之間切換時如何停止播放。 或者有沒有其他方法來ajax。

回答

0

您需要使用jQuery或JavaScript。我使用jQuery和下面的代碼將停止播放視頻時切換標籤。但是,請分配一些類名的UL從其他UI元素

區分
$('document').ready(function() { 
    $('ul > li').click(function() { 
     var $activeVideoIframe = $('.tab-content').find('.active').find('iframe') 
     var playingVideoSrc = $activeVideoIframe.attr('src'); 
     $activeVideoIframe.attr('src', ''); 
     $activeVideoIframe.attr('src', playingVideoSrc); 
    }); 
}); 

這裏是工作的例子 - https://jsfiddle.net/q28h3gb4/