AMP
  • 廣告

投影片廣告

摘要

使用 amp-carousel 的 AMPHTML 廣告範例,建立互動式廣告。

樣式

這是一個進階範例,需要一些樣式才能使其外觀和功能正常運作。

<style amp-custom>
  /* Main element that contains the creative. */
  .root-container {
    font-family: 'Roboto', sans-serif;
    font-size: 12px;
    background: #151717 url(/static/samples/img/car-mesh.jpg) center center;
    background-size: cover;
    color: #fff;
    width: 100%;
    height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .root-container h1 {
    font-weight: normal;
    margin: 10px 0 0;
    text-align: center;
    text-transform: uppercase;
    font-size: 12px;
  }
  .carousel-container {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
    flex-direction: column;
  }
  .carousel-img {
    display: block;
  }
  /*
   * Dimensions of the carousel item are the same as the size of each image
   * plus the border width. Using `calc()` for the sake of the example.
   */
  .carousel-item {
    width: calc(216px + 2 * 4px);
    height: calc(117px + 2 * 4px);
    box-sizing: border-box;
    background: #000;
    float: left;
  }
  .carousel-item .carousel-img {
    border: 4px solid #c9cccc;
  }
  /* Styling for footer */
  .footer {
    background: #000;
    box-sizing: border-box;
    padding: 8px;
    display: flex;
  }
  .stretch {
    flex: 1;
  }
  .logo-img {
    display: block;
  }
  .button {
    text-transform: uppercase;
    padding: 8px;
    color: #fff;
    display: inline-block;
    background-color: #2979ff;
  }
  .button-secondary {
    background: transparent;
    border-right: 1px solid white;
    margin-right: 8px;
  }
</style>

我們使用 amp-carousel 元件來顯示多個投影片。

所有具有 carousel-item 類別名稱的元素基本上都具有相同的標記。

AMP 具有事件和動作的系統。它使用特定領域語言來描述動作如何被觸發。在此範例中,我們結合使用動作系統和 amp-bind,以保留目前選取投影片的狀態變數。

這僅用於在選取項目滑入檢視畫面時啟動的轉場效果。如果不需要轉場效果,則 amp-bind 不再是此範例的必要條件。

<amp-carousel
    height="132"
    layout="fixed-height"
    type="slides"
    class="carousel"
    controls>
  <div class="carousel-item">
    <amp-img src="/static/samples/img/car-sideview2.jpg"
        width="216"
        height="117"
        layout="fixed"
        class="carousel-img"></amp-img>
  </div>
  <div class="carousel-item">
    <amp-img src="/static/samples/img/car-gauges.jpg"
        width="216"
        height="117"
        layout="fixed"
        class="carousel-img"></amp-img>
  </div>
  <div class="carousel-item">
    <amp-img src="/static/samples/img/car-sideview1.jpg"
        width="216"
        height="117"
        layout="fixed"
        class="carousel-img"></amp-img>
  </div>
</amp-carousel>
</div>

透過使用動作系統,我們可以在點擊「尋找商店」按鈕時啟動燈箱效果。

<div class="footer">
  <div class="stretch">
    <amp-img src="/static/samples/img/car-logo.png"
        width="72"
        height="32"
        layout="fixed"
        class="logo-img"></amp-img>
  </div>
  <a href="https://amp.dev.org.tw/documentation/examples/" target="_blank" class="button button-secondary">
    Locate Store
  </a>
  <a href="https://amp.dev.org.tw/documentation/examples/" target="_blank" class="button">
    Explore
  </a>
</div>
需要更多說明嗎?

如果此頁面上的說明未涵蓋您的所有問題,請隨時與其他 AMP 使用者聯繫,討論您的確切使用案例。

前往 Stack Overflow
未說明的特色功能?

AMP 專案強烈鼓勵您的參與和貢獻!我們希望您能成為我們開放原始碼社群的持續參與者,同時我們也歡迎您針對您特別關注的問題進行一次性貢獻。

在 GitHub 上編輯範例