【发布时间】:2018-08-21 08:58:14
【问题描述】:
我在这里使用引导模式,当我使用 URL 时,这段代码运行良好。但是当我试图从我的本地目录播放视频时。例如,当我使用<iframe width="1280" height="720" id="sampleVideo" src="assets/sample.mp4" frameborder="0" allowfullscreen></iframe> 时,它无法正常工作。问题是每当页面刷新视频在单击播放视频按钮之前自动播放时。
我也尝试使用HTML5 video tag,但问题在于引导模型不起作用。还有?rel=0。我不想使用任何插件。
$(document).ready(function() {
$(".modal").modal('hide');
var url = $("#sampleVideo").attr('src');
$(".modal").on('hide.bs.modal', function() {
$("#sampleVideo").attr('src', '');
});
$(".modal").on('show.bs.modal', function() {
$("#sampleVideo").attr('src', url);
});
});
.teaser {
background-size: cover;
position: relative;
}
.teaser .modal-dialog {
max-width: 100%;
}
.teaser .modal {
padding-right: 0!important;
}
.teaser iframe {
height: 100vh;
width: 100%;
}
.teaser .modal-body {
padding: 0;
margin: 0;
}
.teaser .close {
color: white;
position: absolute;
/* background: blue !important; */
border: 0;
top: 0;
z-index: 99999;
right: 3%;
float: none;
opacity: 1;
font-size: 40px;
font-weight: 400;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="teaser container-fluid">
<a href="#videoStory" class="videoBtnbutton more mt-4 d-block" role="button" data-toggle="modal" data-target="#modal-fullscreen">Play Video</a>
<div class="modal modal-fullscreen fade" id="modal-fullscreen" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body" id="yt-player">
<iframe width="1280" height="720" id="sampleVideo" src="https://www.youtube.com/embed/ScMzIvxBSi4" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
</div>
这里的工作代码codepen link here
【问题讨论】:
-
为什么要从本地目录获取视频?如果该站点在服务器上在线,则您可以从 URL 中提取视频。那么本地目录视频有什么用呢?告诉我背后的确切原因。您的网站在线吗?
-
阅读我的问题一次,我想使用本地目录视频。而且我的网站不在线。
标签: video iframe twitter-bootstrap-3 bootstrap-modal