javascript - 视频播放完毕后如何添加自定义按钮
问题描述
因此,我已经使用此 javascript 编写了背景视频播放完毕后出现的其他内容
var vid = document.getElementById("bgvid");
var vid2 = document.getElementById('akiratrailer');
vid.onended = function() {myFunction()};
function myFunction() {
vid2.style.display = "block";
document.getElementById("headline2").innerHTML = "stuff";
document.getElementById("headline3").innerHTML = "stuff";
};
我如何向这个javascript添加一个自定义按钮(我已经有按钮的CSS),以便它可以在背景视频完成后与其他东西一起显示?
这是我的按钮的 html
<a href='newpage.html' class='button'>blah blah blah</a>
我的网站供参考我的网站
解决方案
尝试这个:
var vid = document.getElementById( 'bgvid' ),
vid2 = document.getElementById( 'content' );
vid.onended = function() {
vid2.style.display = 'block';
document.getElementById( 'headline2' ).innerHTML = 'stuff';
document.getElementById( 'headline3' ).innerHTML = 'stuff';
}
* {
box-sizing: border-box
}
body {
margin: 0
}
#bgvid {
position: fixed;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%
}
#content {
display: none;
position: fixed;
overflow-y: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
color: #f1f1f1;
text-align: center
}
#akiratrailer {
margin: 0 auto;
width: 50%
}
.button {
width: 200px;
font-size: 18px;
padding: 10px;
border: none;
background: #000;
color: #fff;
cursor: pointer;
text-decoration: none
}
.button:hover {
background: #ddd;
color: black
}
<video autoplay muted id="bgvid">
<source src="https://www.w3schools.com/howto/rain.mp4" type="video/mp4">
</video>
<div id="content">
<h2 id="headline2"></h2>
<video id="akiratrailer" controls>
<source src="http://andiviaandes.com/videos/akiratrailer.mp4" type="video/mp4">
</video>
<h2 id="headline3"></h2>
<a href='#' class='button'>blah blah blah</a>
</div>
推荐阅读
- python - 选择合适的 azure 服务来部署重复的 python 任务
- javascript - 为什么动态添加的图像的偏移宽度总是为0
- python - 2题:将数据从MySQL数据库导入Python
- ios - 如何在 Swift 中将枚举类型转换为 Double
- javascript - 未捕获的语法错误:Laravel/Vue 应用程序中出现意外的标记“<”
- reactjs - Axios 发布请求未保存
- python - 如何在 Python 中不使用 numpy 将两个稀疏矩阵相乘?
- flutter - 初始化一个在我滑动页面时不会重置其值的变量(颤振)
- javascript - 基于数组对象键值需要setState
- python - 绘制 yticks 以获取来自两列而不是仅一列的数据