AMP
  • stories

amp-story-360

Introduction

The amp-story-360 component embeds 360 images and videos, explorable by gyroscope or animatable between points.

To begin, import amp-story-360 along with your other stories imports.

<script async custom-element="amp-story-360" src="https://cdn.ampproject.org/v0/amp-story-360-0.1.js"></script>

We also import amp-video since we will use a 360 video.

<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>

Basic usage

The amp-story-360 component accepts 1 descendant, an amp-img or amp-video.

On this page we embed a 360 image using amp-img and set a default PoV (point of view).

Use the -start attributes to define the initial PoV:
- heading-start Horizontal angle in degrees. Centered on 0 (default) with a negative angle looking towards the left, positive angle to the right.
- pitch-start Vertical angle in degrees. Centered on 0 (default) at the horizon, with a negative angle looking downwards, positive angle upwards.
- zoom-start This corresponds to a horizontal field of view of 90 degrees. The default is 1. A higher value indicates a narrower field of view.

Photo credit: NASA / JPL / MSSS / Seán Doran.

<amp-story-page id="360-image-1">
  <amp-story-grid-layer template="fill">
    <amp-story-360 layout="fill"
    heading-start="115"
    pitch-start="10"
    zoom-start="1">
      <amp-img
        src="/static/samples/img/amp-story-360.jpg" width="4300" height="2150" alt="...">
      </amp-img>
    </amp-story-360>
  </amp-story-grid-layer>
</amp-story-page>

Defining the animation

Add the -end and duration attributes to animate between the start and end PoV: - heading-end The heading of a complete animation.
- pitch-end The pitch of a complete animation.
- zoom-end The zoom of a complete animation.
- duration How many seconds (s) or milliseconds (ms) an animation takes to complete.

<amp-story-page id="360-image-2">
  <amp-story-grid-layer template="fill">
    <amp-story-360 layout="fill"
      heading-start="115"
      pitch-start="10"
      zoom-start="1"
      heading-end="50"
      pitch-end="-5"
      zoom-end="1.33"
      duration="3s">
      <amp-img
        src="/static/samples/img/amp-story-360.jpg" width="4300" height="2150" alt="...">
      </amp-img>
    </amp-story-360>
  </amp-story-grid-layer>
</amp-story-page>

Gyroscope controls

Add controls="gyroscope" to set the PoV using the devices gyroscope sensor.

If the gyroscope sensor is not available the component will default to animating.
If the device requires permission for the sensor an activate-360 button will display.

Serving over https is required to access the device's gyroscope.

Currently, the amp-story-360 component does not provide any controls for mouse or keyboard users.

<amp-story-page id="360-image-3">
  <amp-story-grid-layer template="fill">
    <amp-story-360 layout="fill"
      heading-start="115"
      pitch-start="10"
      zoom-start="1"
      heading-end="50"
      pitch-end="-5"
      zoom-end="1.33"
      duration="3s"
      controls="gyroscope">
      <amp-img
        src="/static/samples/img/amp-story-360.jpg" width="4300" height="2150" alt="...">
      </amp-img>
    </amp-story-360>
  </amp-story-grid-layer>
</amp-story-page>

amp-video

We use the same attributes for this component but pass an amp-video child.

Video credit: NASA.

<amp-story-page id="360-video-1">
  <amp-story-grid-layer template="fill">
    <amp-story-360 layout="fill"
      heading-start="30" 
      pitch-start="20" 
      zoom-start="1"
      heading-end="-20" 
      pitch-end="10" 
      zoom-end="1.33"
      duration="3s"
      controls="gyroscope">
      <amp-video poster="img/amp-story-360-video-cover.jpg" autoplay layout="fill" loop>
        <source src="/static/samples/video/amp-story-360.mp4" type="video/mp4" />
      </amp-video>
    </amp-story-360>
  </amp-story-grid-layer>
</amp-story-page>

More Resources

If you want to learn more about 360 content for Web Stories, head over to the documentation.

需要进一步说明?

如果此页面上的说明未能涵盖您的所有问题,欢迎与其他 AMP 用户取得联系,讨论您的具体用例。

前往 Stack Overflow
一项无法解释的功能?

AMP 项目强烈鼓励您参与并做出贡献!我们希望您能成为我们开放源代码社区的持续参与者,但我们也欢迎您对所热衷问题做出一次性贡献。

编辑 GitHub 上的示例