SYNCER

SYNCER

<amp-gfycat> - Gfycatの画像を埋め込み表示する

1件

公開日:

AMPのamp-gfycatは、Gfycatの画像を埋め込み表示するための要素です。

概要

名前
amp-gfycat
可用性
Stable (安定)
サポートするレイアウト
fill,fixed,fixed-height,flex-item,responsive
必要なスクリプト
<script async custom-element="amp-gfycat" src="https://cdn.ampproject.org/v0/amp-gfycat-0.1.js"></script>
検証
https://github.com/ampproject/amphtml/blob/master/extensions/amp-gfycat/0.1/validator-amp-gfycat.protoascii
ドキュメント
https://www.ampproject.org/docs/reference/extended/amp-gfycat.html

属性

data-gfyid

指定例: ThatDefinitiveAyeaye

画像ID。

height

指定例: 150

高さ。

noautoplay

この属性を付けると、GIFが再生ボタンを押さないとアニメーションしないようになる。論理属性。

デモを見る

width

指定例: 200

横幅。

共通属性

AMPの全てのタグで利用できる共通属性を指定できます。

説明

ライブラリの読み込み

amp-gfycatを利用するには、専用のライブラリを読み込む必要があります。

HTML

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

画像IDの確認

Gfycatの画像IDはコンテンツのパーマリンクで確認できます。

パーマリンク

https://gfycat.com/ThatDefinitiveAyeaye[LINK]

HTML

<amp-gfycat
	data-gfyid="ThatDefinitiveAyeaye"
	width="640"
	height="360"
	layout="responsive">
</amp-gfycat>

デモを開く

サイズの指定

横幅と高さは画像のアスペクト比を反映するように指定しないと、表示が崩れてしまいます。Fixed iFRAMEの埋め込み用コードで確認できます。

横幅と高さ

<iframe src='https://gfycat.com/ifr/ThatDefinitiveAyeaye' frameborder='0' scrolling='no' width='640' height='360' allowfullscreen></iframe>

サンプルコード

HTML

<!doctype html>
<html amp>
	<head>
		<meta charset="utf-8">
		<title>【デモ】<amp-gfycat> - Gfycatの画像を埋め込み表示する</title>
		<link rel="canonical" href="https://syncer.jp/Web/AMP/Component/amp-gfycat/">
		<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
		<style amp-custom>
			body {
				padding: 12px ;
				background-color: #fff ;
			}

			.container {
				width: 640px ;
				max-width: 95% ;
			}
		</style>
		<script type="application/ld+json">
			{
				"@context": "http://schema.org",
				"@type": "NewsArticle",
				"headline": "記事のタイトル",
				"image": [
					"eyecatch.jpg"
				],
				"datePublished": "2017-08-23T00:00:00+0900"
			}
		</script>
		<script async custom-element="amp-gfycat" src="https://cdn.ampproject.org/v0/amp-gfycat-0.1.js"></script>
		<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
		<script async src="https://cdn.ampproject.org/v0.js"></script>
	</head>
	<body>

<div class="container">

	<amp-gfycat
		data-gfyid="ThatDefinitiveAyeaye"
		width="640"
		height="360"
		layout="responsive">
	</amp-gfycat>

</div>

	</body>
</html>

デモを開く

デモ

</head><body>までを含めて下さい。

</body> </html>

<style amp-custom>

</style>