javascript - How to stop video after 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>
here use bootstrap ajax. switch between video , play. how can stop play when switching between videos. or there other way ajax.
you need use jquery or javascript. used jquery , below code stop video playing while switching between tabs. please assign classname ul differentiate other ul elements
$('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); }); });
here working example - https://jsfiddle.net/q28h3gb4/
Comments
Post a Comment