2

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

但是,由于 amp 的on="enter..."操作,标题会显示在加载时间事件上。我试图找到一种基于另一个元素的位置来隐藏它的方法,但我无法让它与 amp 上可用的功能一起使用,这些功能似乎只是诸如此类的东西height, width......这不是我想要的。

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

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

<!doctype html>
<html ⚡&gt;

<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活动结束后看到标题。目前它在页面加载后显示以下内容:

在此处输入图像描述

如您所见,标题覆盖在后面。

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

非常感谢任何帮助或指出我正确的方向。

4

0 回答 0