简介:iframe视频是嵌入在HTML页面中的内嵌框架视频,但是在AMP HTML中,我们使用名为amp-iframe-video的组件将视频嵌入具有amp-iframe-video的页面中,我们可以使用JavaScript嵌入custom-built视频播放器。
必需的脚本:将amp-video-iframe组件导入标头。
<script async custom-element="amp-video-iframe" src=
"https://cdn.ampproject.org/v0/amp-video-iframe-0.1.js">
</script>
属性:
- src:指定要嵌入的iframe视频的URL或路径。
- poster:加载视频时指向图像URL。这是必填属性。
- implements-media-session:如果iframe应该实现MediaSession API,则应指定此属性。
- implements-rotate-to-fullscreen:当iframe内的文档实现时,该属性为True单独旋转到全屏。
- autoplay:如果设置了该属性,则视频将在视频加载后立即开始播放。
例:
<!DOCTYPE html>
<html amp>
<head>
<meta charset="utf-8" />
<title>GeeksforGeeks amp-video-iframe</title>
<link rel="canonical" href=
"https://amp.dev/documentation/examples/components/amp-video-iframe/index.html" />
<meta name="viewport" content=
"width=device-width,
minimum-scale=1,
initial-scale=1" />
<!-- Include the `amp-video-iframe` component -->
<script async custom-element="amp-video-iframe"
src="https://cdn.ampproject.org/v0/amp-video-iframe-0.1.js">
</script>
<style amp-boilerplate>
body {
-webkit-animation:-amp-start 8s
steps(1, end) 0s 1 normal both;
-moz-animation:-amp-start 8s
steps(1, end) 0s 1 normal both;
-ms-animation:-amp-start 8s
steps(1, end) 0s 1 normal both;
animation:-amp-start 8s
steps(1, end) 0s 1 normal both;
}
@-webkit-keyframes -amp-start {
from {
visibility:hidden;
}
to {
visibility:visible;
}
}
@-moz-keyframes -amp-start {
from {
visibility:hidden;
}
to {
visibility:visible;
}
}
@-ms-keyframes -amp-start {
from {
visibility:hidden;
}
to {
visibility:visible;
}
}
@-o-keyframes -amp-start {
from {
visibility:hidden;
}
to {
visibility:visible;
}
}
@keyframes -amp-start {
from {
visibility:hidden;
}
to {
visibility:visible;
}
}
</style>
<noscript>
<style amp-boilerplate>
body {
-webkit-animation:none;
-moz-animation:none;
-ms-animation:none;
animation:none;
}
</style>
</noscript>
<script async src=
"https://cdn.ampproject.org/v0.js">
</script>
</head>
<body>
<amp-video-iframe id="myVideo" src=
"/static/samples/files/amp-video-iframe-videojs.html"
width="6000" height="405"
layout="responsive" autoplay>
<amp-img placeholder src=
"/static/samples/img/amp-video-iframe-sample-placeholder.jpg"
layout="fill">
</amp-img>
</amp-video-iframe>
</body>
</html>
输出:
相关用法
- Google AMP amp-ad用法及代码示例
- Google AMP amp-accordion用法及代码示例
- Google AMP amp-facebook-like用法及代码示例
- Google AMP amp-carousel用法及代码示例
- Google AMP amp-date-countdown用法及代码示例
- Google AMP amp-brightcove用法及代码示例
- Google AMP amp-bind-recaptcha用法及代码示例
- Google AMP amp-autocomplete用法及代码示例
- Google AMP amp-img用法及代码示例
- Google AMP amp-image-lightbox用法及代码示例
- Google AMP amp-lightbox-gallery用法及代码示例
- Google AMP amp-soundcloud用法及代码示例
- Google AMP amp-mustache用法及代码示例
注:本文由纯净天空筛选整理自somsagar2019大神的英文原创作品 Google AMP amp-video-iframe。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。