在 AMP 页面中集成故事
Web Stories 是一种全屏沉浸式内容体验,用户可以按照自己的节奏点击或滑动浏览。它们存在于开放的网络上,拥有自己的 URL,易于分享。本指南将教您如何在有效的 AMP 页面中集成 Web Stories,并将其呈现给读者。
包含 amp-story-player
Web Stories 依赖于 amp-story-player
组件 在有效的 AMP 站点上集成和播放故事。通过在文档的 head 中包含自定义脚本来实施 amp-story-player
。
<script async custom-element="amp-story-player" src="https://cdn.ampproject.org/v0/amp-story-player-0.1.js"></script>
然后将 amp-story-player
元素 HTML 放置在页面 <body>
中所需的位置。
<head>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script
async
custom-element="amp-story-player"
src="https://cdn.ampproject.org/v0/amp-story-player-0.1.js"
></script>
</head>
<body>
<amp-story-player layout="fixed" width="360" height="600">
<a href="https://preview.amp.dev/documentation/examples/introduction/stories_in_amp/">
<img src="https://amp.org.cn/static/samples/img/story_dog2_portrait.jpg" width="360" height="600" loading="lazy" data-amp-story-player-poster-img alt="...">
Stories in AMP - Hello World
</a>
</amp-story-player>
</body>
显示 Web Story
通过在 <amp-story-player>
元素中包含一个 <a>
标签,并将 href
属性指向所需的 Web Story URL,链接到 Web Story。href
端点可以是托管的 Web Story 的 URL 或相对路径。将故事的标题放在 <a>
标签内。
指定多个 Web Story
在 <amp-story-player>
元素中包含所需数量的 <a>
标签,每个标签的 href
属性都指向所需的 Web Story URL。
<head>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script
async
custom-element="amp-story-player"
src="https://cdn.ampproject.org/v0/amp-story-player-0.1.js"
></script>
</head>
<body>
<amp-story-player layout="fixed" width="360" height="600">
<a href="https://ampfest-story-player-demo.web.app/examples/amp-story/AMPFestPlayerDemo/s1"></a>
<a href="https://ampfest-story-player-demo.web.app/examples/amp-story/AMPFestPlayerDemo/s2"></a>
<a href="https://ampfest-story-player-demo.web.app/examples/amp-story/AMPFestPlayerDemo/s3"></a>
</amp-story-player>
</body>
在故事之间导航
移动设备上的用户可以使用“滑动”手势导航到下一个故事。桌面用户必须点击浏览整个 Web Story 才能查看下一个故事。