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.tw/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