amp-carousel組件用於在AMP HTML中沿水平軸製作圖像/內容輪播。輪播是一係列圖像的幻燈片顯示。
必需的腳本:在標題中導入amp-carousel組件。
HTML
<script async custom-element="amp-carousel" src=
"https://cdn.ampproject.org/v0/amp-carousel-0.1.js">
</script>
屬性:
- type:它指定輪播的類型。默認情況下,類型設置為輪播(所有幻燈片均水平滾動,此處的幻燈片可能具有不同的CSS)。也可以將其設置為幻燈片(一次顯示單個幻燈片)。
- control:它顯示用於用戶導航的左右箭頭。
- autoplay:當我們使用此屬性時,它會自動移動輪播。
- loop:使用循環屬性進行循環,即在最後一張幻燈片中有右控件,在第一張幻燈片中有左控件。
- delay:默認情況下,下一張幻燈片的顯示持續時間設置為5000ms,並且延遲不能小於1000ms。
- slide:它用於指定應該先放哪個幻燈片。
範例1:使用type =“ slides”將圖像列表顯示為幻燈片。
HTML
<!doctype html>
<html amp>
<head>
<meta charset="utf-8">
<title>amp-carousel</title>
<script async src=
"https://cdn.ampproject.org/v0.js">
</script>
<!-- Import the carousel component in the header. -->
<script async custom-element="amp-carousel"
src=
"https://cdn.ampproject.org/v0/amp-carousel-0.1.js">
</script>
<link rel="canonical" href=
"https://amp.dev/documentation/examples/components/amp-carousel/index.html">
<meta name="viewport" content=
"width=device-width,minimum-scale=1,initial-scale=1">
<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>
</head>
<body>
<amp-carousel width="400" height="300"
layout="responsive" type="slides">
<amp-img src=
"https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png"
width="400" height="300"
layout="responsive">
</amp-img>
<amp-img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190918234528/colorize1.png"
width="400" height="300"
layout="responsive">
</amp-img>
<amp-img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190918234815/colorize2.png"
width="400" height="300"
layout="responsive">
</amp-img>
</amp-carousel>
</body>
</html>
輸出:
範例2:使用具有3000ms延遲的自動播放屬性。
HTML
<!doctype html>
<html amp>
<head>
<meta charset="utf-8">
<title>amp-carousel</title>
<script async src=
"https://cdn.ampproject.org/v0.js">
</script>
<!-- Import the carousel component
in the header. -->
<script async custom-element="amp-carousel"
src=
"https://cdn.ampproject.org/v0/amp-carousel-0.1.js">
</script>
<link rel="canonical" href=
"https://amp.dev/documentation/examples/components/amp-carousel/index.html">
<meta name="viewport" content=
"width=device-width,minimum-scale=1,initial-scale=1">
<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>
</head>
<body>
<amp-carousel width="400" height="300"
layout="responsive" type="slides"
autoplay delay="3000">
<amp-img src=
"https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png"
width="400" height="300"
layout="responsive">
</amp-img>
<amp-img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190918234528/colorize1.png"
width="400" height="300"
layout="responsive">
</amp-img>
<amp-img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190918234815/colorize2.png"
width="400" height="300"
layout="responsive">
</amp-img>
</amp-carousel>
</body>
</html>
輸出:
相關用法
- Google AMP amp-ad用法及代碼示例
- Google AMP amp-accordion用法及代碼示例
- Google AMP amp-facebook-like用法及代碼示例
- Google AMP amp-date-countdown用法及代碼示例
- Google AMP amp-brightcove用法及代碼示例
- Google AMP amp-bind-recaptcha用法及代碼示例
- Google AMP amp-autocomplete用法及代碼示例
- Google AMP amp-img用法及代碼示例
- Google AMP amp-image-lightbox用法及代碼示例
- Google AMP amp-lightbox-gallery用法及代碼示例
- Google AMP amp-soundcloud用法及代碼示例
- Google AMP amp-mustache用法及代碼示例
注:本文由純淨天空篩選整理自somsagar2019大神的英文原創作品 Google AMP amp-carousel。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。