在 AMP 页面中集成故事
Web Stories 是一种全屏沉浸式内容体验,用户可以按照自己的节奏点击或单击浏览。它们以自己的 URL 存在于开放网络上,使它们易于共享。本指南教您如何在 AMP 有效页面中集成 Web Stories,并将其呈现给读者。
包含 amp-story-player
Web Stories 依赖于 amp-story-player
组件 在 AMP 有效站点上集成和播放故事。通过在文档的头部包含自定义脚本来实现 amp-story-player
。
<script async custom-element="amp-story-player" src="https://cdn.ampproject.org/v0/amp-story-player-0.1.js"></script>
然后在页面的 <body>
中所需的位置放置 amp-story-player
元素 HTML。
<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 才能查看下一个。