HTML5视频自动播放不工作与fullPage.js
HTML5 Video Autoplay not working with fullPage.js
好的,我已经尝试了几乎所有的方法,但我的代码中有些东西阻止了HTML5的自动播放属性
以下是我到目前为止所做的尝试:
- autoplay
- autoplay="autoplay"
- $.fn.fullpage({
scrollOverflow: false,
afterRender: function(){
$('#video')[0].play();
}
});
我还尝试删除jquery.fullPage.js中的部分代码,看看是否使其冲突,但它只是阻止我能够滚动。
/**
* Plays video and audio elements.
*/
function playMedia(destiny){
var panel = getSlideOrSection(destiny);
//playing HTML5 media elements
panel.find('video, audio').each(function(){
var element = $(this).get(0);
if( element.hasAttribute('data-autoplay') && typeof element.play === 'function' ) {
element.play();
}
});
//youtube videos
panel.find('iframe[src*="youtube.com/embed/"]').each(function(){
var element = $(this).get(0);
if ( element.hasAttribute('data-autoplay') ){
playYoutube(element);
}
//in case the URL was not loaded yet. On page load we need time for the new URL (with the API string) to load.
element.onload = function() {
if ( element.hasAttribute('data-autoplay') ){
playYoutube(element);
}
};
});
}
我的HTML
<video id="video" width="100%" height="100%" class="bgvid" style="position: relative; float: left; z-index: 2; opacity: 0.4;" controls muted="muted" autoplay="autoplay">
<source src="images/boston.mp4" class="bgvid">
</video>
<div style="position: absolute; z-index: 100; float: left; margin-top: 15%; margin-left: 5%;">
<span class="title"> Web Design and Entertainment </span><br>
<span style="font-size: 22px; font-weight: 500; font-family: 'Raleway', sans-serif; color: black;"> right in the heart of Boston. </span>
<br><br>
<hr style="border: 1px solid red;">
<br>
<span style="font-size: 19px; font-weight: 500; font-family: 'Raleway', sans-serif; color: black;">We're a <span class="red">web design</span>, <span class="red">software engineering</span>, and <br><span class="red">entertainment</span> company to help you grow <br>your business online. </span>
<br><br><br><br>
<a href="ourwork.html" class="workbtn">SEE OUR WORK <i class="fa fa-angle-double-right"></i></a>
</div>
你不需要使用自动播放,甚至使用afterRender
回调手动播放。
请按照fullPage.js文档中关于自动播放嵌入媒体元素的详细说明使用data-autoplay
。
<audio data-autoplay>
<source src="http://metakoncept.hr/horse.ogg" type="audio/ogg">
</audio>
这样你也可以决定是否想要fullPage.js在section/slide leave时自动暂停(通过使用data-keepplaying
或不)
作者提供了一种解决方法,这个作品适合我
$.fn.fullpage({
scrollOverflow: false,
afterRender: function(){
$('#video')[0].play();
}
});
这里(Github fullPage issue)是一个链接,你可以获得更多关于这个问题的信息
相关文章:
- Fullpage.js-视频+背景在同一部分
- fullpage.js和物化.js;使用实体侧导航禁用鼠标滚动
- 如何在特定条件下完全禁用FullPage.js
- 更改事件的fullPage.js选项
- fullpage.js在滚动时更改滚动方向
- 如何使用鼠标滚动控制fullPage.js垂直滑块
- Fullpage.js and SlimScroll
- Fullpage.js+figcaption+懒洋洋淡出
- 使用fullpage.js时,使用键盘自动滚动,但仅限于某些部分
- fullPage.js在使用scrollOverflow时未检测到动态生成内容的高度
- 我们如何在fullPage.js中为不同的部分制作不同的填充顶部和底部值
- Magic Line在使用键盘上下移动时未使用fullPage.js进行更新
- Fullpage.js在横向模式下无法在iOS上正常缩放
- Webflow和Fullpage.js相互干扰
- fullPage.js滚动条:true使浏览器随deelay一起移动
- Fullpage.js.添加滚动延迟
- Fullpage.js不能在Mozilla上运行,但在Chrome上运行良好
- 为什么css悬停与javascript(fullpage.js)交互,我该如何停止它
- fullpage.js在节之间添加了2个自动滚动事件
- 全页面滚动插件(fullPage.js、scrollify.js等)阻止默认的移动Safari UI行为