【发布时间】:2017-01-19 02:13:30
【问题描述】:
再次向 SO 社区问好!我有一个使用 Avada 主题的 Wordpress 站点,该主题在其原生“Fusion Builder”页面构建器中带有一个开箱即用的模式元素。我使用 iframe 代码在模态中嵌入了 YouTube 视频,并将模态链接到我主页上的“播放”按钮。目前,您必须按下“播放”按钮以启动弹出窗口(模式),然后再次按下播放以开始播放视频。我希望视频在模式窗口中打开后立即开始播放,这样用户就不必按两次播放。我发现这比我想象的要困难。
这是我的网站:http://8d2.b73.myftpupload.com/
我不会写 jquery,只会 HTML 和 CSS。但是,我对阅读 jquery 有点熟悉。我目前正在使用从另一个 SO 搜索中获得的这段代码(如下)。它不工作。我正在使用插件将代码插入标题中。
var videoSrc = $("#homepage-video iframe").attr("src");
$('#homepage-video').on('show.bs.modal', function () { // on opening the modal
// set the video to autostart
$("#homepage-video iframe").attr("src", videoSrc+"&autoplay=1");
});
$("#homepage-video").on('hidden.bs.modal', function (e) { // on closing the modal
// stop the video
$("#homepage-video iframe").attr("src", null);
});
这是我的模态 HTML 代码,虽然我使用页面构建器来创建和管理模态,技术上使用短代码,所以我并没有真正看到或对这段代码做任何事情:
<div class="fusion-modal modal fade modal-1 homepage-video" tabindex="-1" role="dialog" aria-labelledby="modal-heading-1" aria-hidden="true" id="homepage-video" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content fusion-modal-content" style="background-color:#f6f6f6">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="modal-title" id="modal-heading-1" data-dismiss="modal" aria-hidden="true" data-fontsize="25" data-lineheight="31"></h3>
</div>
<div class="modal-body">
<p><iframe src="https://www.youtube-nocookie.com/embed/BLFCOVea3yU?rel=0&showinfo=0" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
</div>
</div>
</div>
</div>
我不确定 Avada 是否本机使用引导程序——我不确定主题是基于什么构建的。因此,以防万一我的 jquery 代码由于主题未使用引导程序而无法正常工作,我将以下内容插入到标题中:
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
从我能够阅读的内容来看,我的 jquery 看起来是正确的,而且似乎一切都已正确设置。但是,没有任何工作。有没有代码天才看到这个问题?
【问题讨论】:
-
更新:事实证明这根本不需要代码,这太棒了!请参阅下面的答案,并务必阅读 cmets 了解详细信息。
标签: jquery wordpress twitter-bootstrap youtube bootstrap-modal