From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/htmlmediaelement/play_event/index.html | 120 +++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 files/zh-cn/web/api/htmlmediaelement/play_event/index.html (limited to 'files/zh-cn/web/api/htmlmediaelement/play_event/index.html') diff --git a/files/zh-cn/web/api/htmlmediaelement/play_event/index.html b/files/zh-cn/web/api/htmlmediaelement/play_event/index.html new file mode 100644 index 0000000000..c9b39495fd --- /dev/null +++ b/files/zh-cn/web/api/htmlmediaelement/play_event/index.html @@ -0,0 +1,120 @@ +--- +title: 'HTMLMediaElement: play event' +slug: Web/API/HTMLMediaElement/play_event +translation_of: Web/API/HTMLMediaElement/play_event +--- +

{{APIRef("HTMLMediaElement")}}

+ +

当 paused 属性由 true 转换为 false 时触发 play 事件,事件触发原因一般为 play() 方法调用,或者 autoplay 标签设置。

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BubblesNo
CancelableNo
Interface{{DOMxRef("Event")}}
TargetElement
Default ActionNone
Event handler property{{domxref("GlobalEventHandlers.onplay")}}
SpecificationHTML5 media
+ +

Examples

+ +

下方的例子监听了 HTMLMediaElement 标签的 play 事件,并且在事件触发后在控制台打印相应的信息。

+ +

Using addEventListener():

+ +
const video = document.querySelector('video');
+
+video.addEventListener('play', (event) => {
+  console.log('The Boolean paused property is now false. Either the ' +
+  'play() method was called or the autoplay attribute was toggled.');
+});
+ +

Using the onplay event handler property:

+ +
const video = document.querySelector('video');
+
+video.onplay = (event) => {
+  console.log('The Boolean paused property is now false. Either the ' +
+  'play() method was called or the autoplay attribute was toggled.');
+};
+ +

Specifications

+ + + + + + + + + + + + + + + + +
SpecificationStatus
{{SpecName('HTML WHATWG', "media.html#event-media-play", "play media event")}}{{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', "embedded-content-0.html#event-media-play", "play media event")}}{{Spec2('HTML5 W3C')}}
+ +

Browser compatibility

+ + + +

{{Compat("api.HTMLMediaElement.play_event")}}

+ + + + + +

See Also

+ + -- cgit v1.2.3-54-g00ecf