91
rated 0 times
[
97]
[
6]
/ answers: 1 / hits: 21874
/ 5 Years ago, fri, february 1, 2019, 12:00:00
I'm looking for a way to dynamically display a video in a modal pop-up, without being embedded to YouTube.
$(function() {
$(.video).click(function () {
var theModal = $(this).data(target),
videoSRC = $(this).attr(data-video),
videoSRCauto = videoSRC + ;
$(theModal + ' source').attr('src', videoSRCauto);
$(theModal + ' button.close').click(function () {
$(theModal + ' source').attr('src', videoSRC);
});
});
});
<head>
<link rel=stylesheet href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css>
<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js></script>
<script src=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js></script>
</head>
<button class=btn btn-lg video data-video=https://clienti.dk/media/1140/friheden-video.mp4 data-toggle=modal data-target=#videoModal>Play Video</button>
<div class=modal fade id=videoModal tabindex=-1 role=dialog aria-labelledby=myModalLabel aria-hidden=true>
<div class=modal-dialog>
<div class=modal-content>
<div class=modal-body>
<button type=button class=close data-dismiss=modal aria-label=Close><span aria-hidden=true>×</span></button>
<video controls>
<source src= type=video/mp4>
</video>
</div>
</div>
</div>
</div>
YouTube Iframe
- Working example with embedded youtube video in iframe
Regular video
- Here I tried to use html video instead. The video gets the right src
but it might be a problem with load timing.
Can anyone help me out?
More From » jquery