AMP

Important: this documentation is not applicable to your currently selected format email!

amp-tiktok

Experimental

Description

Displays a TikTok video embed.

 

Required Scripts

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

Usage

The amp-tiktok component embeds a TikTok video on your page.

<amp-tiktok
  width="325"
  height="575"
  data-src="6718335390845095173"
></amp-tiktok>

Behavior

The amp-tiktok component displays the TikTok video in an iframe. You may specify the width, height and data-src attributes. amp-tiktok does not support autoplay and requires user interaction to play videos.

Avoiding Layout shift

Prevent layout shift by matching the width and height attributes on the amp-tiktok element to the size of the video player.

By default, the width of the amp-tiktok iframe is 325px, resulting in a hight of roughly 575px. The default height of the embedded TikTok video player depends on the length and content of the TikTok caption. To show the entire video, the amp-tiktok component resizes to match the player height. You can avoid this by defining the width and height to match the video player.

<amp-tiktok
  width="325"
  height="731"
  data-src="6718335390845095173"
></amp-tiktok>
이 코드 조각을 Playground에서 열기

If you choose to set the width to a value which is greater than 325px, the iframe will remain 325px and will be horizontally centered in that space. The surrounding space will be empty.

If you choose to set the height of to a value which is which is greater than the height the height will remain the height of the iframe.

Placeholder

There are two ways to set a placeholder image:

  • Pointing the data-src attribute to the image URL
  • Pointing the TikTok provided cite attribute, made available through blockquote, to the image URL.

Attributes

data-src

The data-src attribute can contain one of two values: a video id or a full URL to a TikTok detail page.

Example with video-id

<amp-tiktok
  width="325"
  height="575"
  data-src="6948210747285441798"
></amp-tiktok>
이 코드 조각을 Playground에서 열기

Example with source url:

<amp-tiktok
  width="325"
  height="575"
  data-src="https://www.tiktok.com/@scout2015/video/6948210747285441798"
></amp-tiktok>
이 코드 조각을 Playground에서 열기

In lieu of the data-src attribute, amp-tiktok also allows the use of the TikTok generated embed code to display.

To use this method copy the blockquote from the TikTok Embed code:

  1. Refer to the (TikTok embed documentation)[https://developers.tiktok.com/doc/Embed] to find the embed code for your TikTok.
  2. Copy the embed code and add it as a child element of the amp-tiktok element.
  3. Add the placeholder attribute to the blockquote.
  4. Remove the style attribute from the blockquote.
@countingprimes

VIM is great.... right up until you start typing the commands into every single text editor you see. I’d like to apologize for all my unneeded ":wq"’s

♬ original sound - countingprimes
<amp-tiktok width="300" height="800">
<blockquote
  placeholder
  class="tiktok-embed"
  cite="https://www.tiktok.com/@countingprimes/video/6948210747285441798"
  data-video-id="6948210747285441798"
>
  <section>
    <a
      target="_blank"
      title="@countingprimes"
      href="https://www.tiktok.com/@countingprimes"
      >@countingprimes</a
    >
    <p>
      VIM is great.... right up until you start typing the commands into every
      single text editor you see. I’d like to apologize for all my unneeded
      ":wq"’s
    </p>
    <a
      target="_blank"
      title="♬ original sound - countingprimes"
      href="https://www.tiktok.com/music/original-sound-6948210588145175302"
      >♬ original sound - countingprimes</a
    >
  </section>
</blockquote>
</amp-tiktok>
이 코드 조각을 Playground에서 열기

Accessibility

If the user provides an aria-label then that label will be propogated to the iframe. If the user proides an oEmbed source URL as the data-src then the TikTok's caption will be used as the aria-label with the format 'Tiktok: "Caption"'. Otherwise the aria-label will default to 'TikTok'.

도움이 더 필요하신가요?

이 문서를 수십 번 읽었음에도 여전히 궁금한 점이 남아 있나요? 다른 개발자들도 같은 심정일지 모릅니다. Stack Overflow에서 소통해 보세요.

Stack Overflow로 이동
버그나 누락된 기능을 발견하셨나요?

AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.

GitHub로 이동하기