amp-animation onload运行关键帧

时间:2019-01-07 08:03:21

标签: html css amp-html amp-animation

我试图仅在用户向上滚动时显示标题,为此,我设法在用户开始滚动后使其开始工作。

但是,由于放大器的on="enter..."动作,在加载时间事件上显示标题。我试图找到一种基于其他元素的位置将其隐藏的方法,但是我无法使其与amp上可用的功能一起使用,而这些功能似乎只是像height, width之类的东西。我想要的。

  • 我想基于header元素的Y位置显示.spacer

这是到目前为止我能想到的:

<!doctype html>
<html ⚡>

<head>
  <meta charset="utf-8">
  <link rel="canonical" href="https://www.ampstart.com/templates/article.amp">
  <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>
  <script async="" src="https://cdn.ampproject.org/v0.js"></script>
  <script custom-element="amp-animation" src="https://cdn.ampproject.org/v0/amp-animation-0.1.js" async></script>
  <script custom-element="amp-position-observer" src="https://cdn.ampproject.org/v0/amp-position-observer-0.1.js" async></script>

  <style amp-custom>
    body {
      font-family: Helvetica, sans-serif;
    }

    main {

      padding: 10px;
      max-width: 412px;
      margin: auto;
    }

    header {
      width: 100%;
      padding: 10px 0;
      background: #fff;
      top: 0;
      box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.08);
      position: relative;
      transform: translateY(-100%);
    }

    header h1 {
      font-size: 30px;
      text-indent: 40px;
      font-weight: bold;
      margin: 0;
    }

    .spacer {
      height: 100vh;
      width: 100%;
      background-image: -webkit-linear-gradient(#EEE 50%, white 50%);
      background-image: linear-gradient(#EEE 50%, white 50%);
      background-size: 100% 3em;
      transform: translateY(-60px);
    }

    #marker {
      position: relative;
      /*top: 50px;*/
      width: 0px;
      height: 0px;
    }
  </style>
</head>

<body>
<header>
  <h1>Show Header</h1>
</header>
<amp-animation id="hideAnim" layout="nodisplay">
  <script type="application/json">
    {
      "easing": "ease-out",
      "duration": "500ms",
      "fill": "both",
      "iterations": "1",
      "direction": "alternate",
      "animations": [{
        "selector": "header",
        "keyframes": [{
          "transform": "translateY(-60px)"
        },
          {
            "transform": "translateY(0)"
          }
        ]
      }
      ]
    }
  </script>
</amp-animation>

<amp-animation id="scrollToAnim"
               layout="nodisplay">
  <script type="application/json">
    {
      "easing": "ease-in",
      "duration": "0",
      "fill": "both",
      "iterations": "1",
      "direction": "alternate",
      "animations": [{
        "selector": ".spacer",
        "keyframes": [{
          "transform": "translateY(-60px)"
        },
          {
            "transform": "translateY(0)"
          }
        ]
      }]
    }
  </script>
</amp-animation>

<main>
  <!-- Invisible 0x0px marker div that sits 100px off the top -->
  <div id="marker">
    <amp-position-observer on="enter:hideAnim.start; exit:hideAnim.start, hideAnim.reverse, scrollToAnim.start;" layout="nodisplay">
    </amp-position-observer>
  </div>
  <div id="default" class="spacer"></div>
  <div class="spacer"></div>
</main>
</body>

</html>

我不想在onload事件之后看到标题。当前,页面加载后会显示以下内容:

enter image description here

如您所见,标头覆盖在背面。

  • 我不想在加载时间看到标题。

非常感谢您的帮助或为我指明正确的方向。

0 个答案:

没有答案