AMP:amp-accordion不工作

时间:2016-03-08 19:54:29

标签: amp-html

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

的放大器页面中尝试来自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> 
标题中的

,我得到以下两个(令人不安的)错误消息:

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.

有什么想法吗?

4 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

According to this page,它似乎是一个实验性组件,必须是manually enabled here并在控制台中使用以下javascript行:

.Where(x => x.Agency == air.agency ).Take(10);

答案 2 :(得分:1)

虽然它是实验性的,但有必要启用它。请注意,仅仅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>

答案 3 :(得分:0)

在头标记中添加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>