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.

Bạn cần được giải thích thêm?

Nếu bạn vẫn còn thắc mắc sau khi đọc hướng dẫn trên trang này, hãy liên hệ với những người dùng AMP khác để thảo luận về trường hợp sử dụng cụ thể của bạn.

Truy cập Stack Overflow
Một tính năng chưa được giải thích?

Dự án AMP đặc biệt khuyến khích sự tham gia và đóng góp của bạn! Chúng tôi hi vọng bạn sẽ trở thành một người tham gia tích cực trong cộng đồng mã nguồn mở của chúng tôi, nhưng chúng tôi cũng chào mừng các đóng góp đơn lẻ về vấn đề mà bạn đặc biệt quan tâm.

Chỉnh sửa mẫu trên GitHub