Home > Web Front-end > H5 Tutorial > body text

H5 sets or returns the currentTime property of the current position (in seconds) of audio/video playback

黄舟
Release: 2017-11-08 11:02:30
Original
3968 people have browsed it

Example

Set the time position to 5 seconds:

myVid=document.getElementById("video1");
myVid.currentTime=5;
Copy after login

Definition and usage

currentTime property sets or returnsAudio/ The current position of video in seconds.

When this property is set, playback will jump to the specified position.

Browser support

All major browsers support the currentTime attribute.

Note: This attribute is not supported in Internet Explorer 8 or earlier browsers.

Syntax

Set currentTime attribute:

audio|video.currentTime="seconds"
Copy after login

Return currentTime attribute:

audio|video.currentTime
Copy after login

Attribute value

ValueDescription
secondsIndicates the current position of audio/video playback in seconds.

Technical details

Return valueNumeric value, representing seconds

Example

Set the time position to 5 seconds:

<!DOCTYPE html> 
<html> 
<body> 

<p>
	<button onclick="getCurTime()" type="button">获得当前时间的位置</button>
	<button onclick="setCurTime()" type="button">把时间位置设置为 5 秒</button>
</p>

<video id="video1" controls="controls">
	<source src="/kf51/demo/mov_bbb.mp4" type="video/mp4">
	<source src="/kf51/demo/mov_bbb.ogg" type="video/ogg">
	您的浏览器不支持 video 标签。
</video>

<script>
var myVid = document.getElementById("video1");
function getCurTime() { 
	alert(myVid.currentTime);
} 
function setCurTime() { 
	myVid.currentTime = 5;
} 
</script> 

</body> 
</html>
Copy after login


The above is the detailed content of H5 sets or returns the currentTime property of the current position (in seconds) of audio/video playback. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!