iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 10
0
Modern Web

AMP系列 第 10

AMP(Lession 10) - 收合區域

收合區域 - amp-accordion

如下圖所示:
https://ithelp.ithome.com.tw/upload/images/20180929/20078336hnntPuthkN.png

如手風琴(accordion)一般,開合以顯示內容

Required Script

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

基本架構

<amp-accordion disable-session-states>
  <section>
    <h2>Section 1</h2>
    <p>Content in section 1.</p>
  </section>
  <section>
    <h2>Section 2</h2>
    <div>Content in section 2.</div>
  </section>
  <section expanded>
    <h2>Section 3</h2>
    <amp-img src="images/squirrel.jpg"
      width="320"
      height="256"></amp-img>
  </section>
</amp-accordion>
  • 每一個 <amp-accordion> 中可以包含1個以上的 <section>
  • 每一個 <section> 會包含2部分
    • 第一部分是該區域的 header ( Header 元件),可以是 <h1> , <h2> , ... , <h6> , <header>
    • 第二部分則是該區域的主要內容( Content 元件),可為任意的 tag

Events & Actions

| Event | Action | Description
:------------ | :------------ | :------------ | :------------
expand | Y | Y | 展開以顯示該區域
collapse | Y | Y | 收縮以隱藏該區域
trigger | N | Y | 切換 expand & trigger 的狀態

Attributes

Attribute Tag Description
animate <amp-accordion> 當開合 <section> 區域時, height 會有動畫效果的改變
disable-session-states <amp-accordion> 使原本點擊區域的 title (可以是 <h1> , <h2> , ... , <h6> , <header> )達到開合的效果會失效
expanded <section> <section> 區域預設會是展開的(看得見內容)
expand-single-section <amp-accordion> 同時只會有一個 <section> 區域是展開顯示的

Styling

  • <amp-accordion> 永遠是 display: block

  • <section> , 以及它裡面的2大區域元件,不可以是 float-able

  • <section> 被展開時,它會擁有 expanded 這個 attribute

  • Content 元件是 overflow: hidden 故而不會有捲軸

  • <amp-accordion> , <section> , Header , Content 這些元件的 margin 設定都是 0 ,但都可覆寫成客製的 styles

  • Header 與 Content 這2元件都是 position: relative


參考來源:


上一篇
AMP(Lession 9) - AMP中使用Lightbox
下一篇
AMP(Lession 11) - 時間轉換 timeago
系列文
AMP30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言