HTML DOM 视频结束属性
HTML DOM Video 结束属性返回一个布尔值(真/假),表示视频是否播放完毕。
语法
语法如下 −
返回布尔值
mediaObject.ended
我们来看一个 HTML DOM Video ended 属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video ended</title>
<style>
* {
padding: 2px;
margin:5px;
}
form {
width:70%;
margin: 0 auto;
text-align: center;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-Video-ended</legend>
<video id="demo" width="320" controls><source src="https://tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>
<input type="button" onclick="getTrackDetails()" value="How many seconds before the video ends?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var demo = document.getElementById("demo");
function getTrackDetails() {
if(demo.ended === false)
divDisplay.textContent = 'Video ends in: '+(demo.duration - demo.currentTime)+' seconds';
}
</script>
</body>
</html>输出
点击 ‘视频结束前还有多少秒?’ 按钮之前 −

点击 ‘视频结束前还有多少秒?’ 按钮之后 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP