AMP:amp-accordion 不工作

AMP: amp-accordion not working

任何人都可以提供 amp-accordion 的工作示例吗?当我在引用

的 amp 页面中尝试来自 https://www.ampproject.org/docs/reference/extended/amp-accordion.html 的示例代码时
<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script> 

在 header 中,我收到以下两条(令人不安的)错误消息:

The attribute 'custom-element' in tag 'amp-access extension .js script' is set to the invalid value 'amp-accordion'. (see https://www.ampproject.org/docs/reference/extended/amp-access.html)

最后

The tag 'amp-accordion' is disallowed.

有什么想法吗?

According to this page, it seems to be an experimental component and has to be manually enabled here 并在控制台中使用以下行 javascript:

AMP.toggleExperiment('amp-accordion')

虽然它是实验性的,但有必要启用它。请注意,仅仅 toggleExperiment 是不够的,您需要检查实验是否尚未启用。请参阅下面的示例。

<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script>
<script>    
    (window.AMP = window.AMP || []).push(function(AMP) {
       if(!AMP.isExperimentOn('amp-accordion'))
          AMP.toggleExperiment('amp-accordion');
    });
</script>

另外不要忘记为其添加样式:

   <style amp-custom>
        section[expanded] span.expanded {
            display: block;
        }
        section[expanded] span.collapsed {
            display: none;
        }
        section:not([expanded]) span.expanded {
            display: none;
        }
        section:not([expanded]) span.collapsed {
            display: block;
        }
   </style>

在此处查找有关如何使用 amp-accordion 的示例: https://ampbyexample.com/components/amp-accordion/

在 head 标签内添加 amp JS 和 amp accordion JS

<!--
  ## Introduction

  An accordion provides a way for viewers to have a glance at the outline of the content and jump to a section or their choice at their will.
-->
<!-- -->
<!doctype html>
<html ⚡>
<head>
  <meta charset="utf-8">
  <title>amp-accordion</title>
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <!-- ## Setup -->
  <!--
    Import the `amp-accordion` component.
  -->
  <script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script>
  <link rel="canonical" href="https://ampbyexample.com/components/amp-accordion/">
  <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>
  <style amp-custom>
  amp-accordion section[expanded] .show-more {
    display: none;
  }
  amp-accordion section:not([expanded]) .show-less {
    display: none;
  }
  .nested-accordion h4 {
    font-size: 14px;
    background-color: #ddd;
  }
  amp-accordion#hidden-header section[expanded] h4 {
    border: none;
  }
</style>
</head>
<body>

  
    <amp-accordion disable-session-states>
      <section>
        <h4>Section 1</h4>
        <p>Bunch of content.</p>
      </section>
      <section>
        <h4>Section 2</h4>
        <amp-accordion class="nested-accordion">
          <section>
            <h4>Nested Section 2.1</h4>
            <p>Bunch of content.</p>
          </section>
          <section>
            <h4>Nested Section 2.2</h4>
            <p>Bunch of more content.</p>
          </section>
        </amp-accordion>
      </section>
    </amp-accordion>
</body>
</html>