示例工程 29-cards-navigation

29-cards-navigation/demo-02-nav/index.html

html · 1.3 KB

运行:粘性导航与移动菜单

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>粘性导航与移动菜单</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <header class="bar">
      <strong>NAV DEMO</strong>
      <nav class="links">
        <a href="#s1">第一节</a>
        <a href="#s2">第二节</a>
        <a href="#s3">第三节</a>
      </nav>
      <button class="menu" type="button" popovertarget="menu" aria-label="打开菜单">☰</button>
    </header>

    <div id="menu" class="drawer" popover>
      <button class="close" type="button" popovertarget="menu" aria-label="关闭菜单">×</button>
      <nav>
        <a href="#s1">第一节</a>
        <a href="#s2">第二节</a>
        <a href="#s3">第三节</a>
      </nav>
    </div>

    <main>
      <section id="s1">
        <h1>第一节</h1>
        <p>滚动页面,顶部导航会粘住。</p>
      </section>
      <section id="s2">
        <h2>第二节</h2>
        <p>点击「第二节」,标题不会被导航遮住,因为设置了 scroll-margin-top。</p>
      </section>
      <section id="s3">
        <h2>第三节</h2>
        <p>窄屏下导航收进右上角菜单;点击按钮打开 popover。</p>
      </section>
    </main>
  </body>
</html>