jquery - Bootstrap modal and multiple vimeo videos -
i have page has multiple videos embedded. each link opens video in bootstraps modal. problem have if close modal video still playing.
i found script force stop next issue page has multiple videos. have tried capture id of each video variable when clicked.
independently 2 scripts have work, bit missing them combined?
html
<ul> <li><a class="video" href="#" data-toggle="modal" data-target="#video1">video 1</a></li> <li><a class="video" href="#" data-toggle="modal" data-target="#video2">video 2</a></li> <li><a class="video" href="#" data-toggle="modal" data-target="#video3">video 3</a></li> <li><a class="video" href="#" data-toggle="modal" data-target="#video4">video 4</a></li> </ul>
this jquery have stop video playing:
$('#video1').on('hidden.bs.modal', function (e) { $('#video1 iframe').attr("src", jquery("#video1 iframe").attr("src")); });
and here variable set capture id of clicked link don't have add each id manually script above:
$('a.video').click(function(e) { editid = $(this).attr("data-target"); alert(editid); });
what struggling find out how add variable , work in first jquery part stops video playing on close.
thanks
you wire handler on first click persist , pass along id. this:
var selector = $(this).attr("data-target"); $(selector).data("hasbeenclicked", true);
but don't need go far. can expand way in you're listening modals close. modal has closed, check see if has iframe inside of it. if so, run script stop playing.
like this:
$('.modal').on('hidden.bs.modal', function (e) { $iframe = $(this).find("iframe"); $iframe.attr("src", $iframe.attr("src")); });
here's full example in plunker
also, have looked @ javascript api. might able find way pause didn't lose buffering or position of video in case comes it.
full code plunker - won't run on snippets because of sandbox
also, here's shorter javascript handler:
$('.modal').on('hidden.bs.modal', function (e) { $(this).find("iframe")[0].src += ""; });
sample html:
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script> <ul class="nav" > <li><a href="#" data-toggle="modal" data-target="#video1">video 1</a></li> <li><a href="#" data-toggle="modal" data-target="#video2">video 2</a></li> </ul> <div class="modal fade" id="video1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" > <span aria-hidden="true">×</span> </button> <h4 class="modal-title">video 1</h4> </div> <div class="modal-body"> <iframe src="//player.vimeo.com/video/108792063" width="500" height="300" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> </div> </div> </div> </div> <div class="modal fade" id="video2"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" > <span aria-hidden="true">×</span> </button> <h4 class="modal-title">video 2</h4> </div> <div class="modal-body"> <iframe src="//player.vimeo.com/video/69593757" width="500" height="300" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> </div> </div> </div> </div>
Comments
Post a Comment