全屏抽屉导航

导航区块HTML/CSS / React / Vue已复制 0 次

给品牌站用的全屏菜单:点右上角按钮,面板从右侧滑入、底层页面后退一层并压暗,菜单条目按 stagger 逐条上浮,底部固定放联系方式——一屏解决"菜单打开了但不知道去哪、也不知道找谁"。层次感由 depth 控制:数值越大,底层后退越明显;模糊强度单独可调。关闭方式给全:关闭按钮、点击遮罩、Esc 键都能收起。靛紫配大字号是它自己的语境,不是给后台管理用的小号菜单。菜单开合只切 body 上的状态类,动画交给 CSS,不靠 JS 逐帧算。强调色、后退深度、模糊、逐条间隔都可改。给的是三框架源码,参数集中在开头的 CONFIG。

组件预览改右侧参数,这里和下方代码同步更新

组件演示加载中

演示在 iframe 里独立运行(1280×720 虚拟视口,等比缩放 40%)。滚动类交互要在框内滚动才看得到。

复制代码

代码跟着右侧参数走:你调的每个值都已经写进代码

<div class="page" id="page">
  <header class="bar">
    <a class="logo" href="#">Nocturne<i></i></a>
    <button class="burger" id="burger" type="button" aria-label="打开菜单" aria-expanded="false" aria-controls="drawer">
      <i></i><i></i>
    </button>
  </header>

  <main class="stage">
    <span class="kicker">Film &amp; sound · Est. 2018</span>
    <h1>We make <em>night</em> things look expensive.</h1>
    <p>影像、声音与现场。我们不接"快一点"的项目,只接值得慢慢做的。</p>
    <span class="hint">
      <svg width="12" height="12" viewBox="0 0 14 14" fill="none" aria-hidden="true">
        <path d="M7 11.2V2.8M3.2 6.6 7 2.8l3.8 3.8" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
      </svg>
      点右上角,看抽屉滑进来
    </span>
  </main>

  <footer>
    <div class="ub-credit-bar" id="credit">
      <a href="https://uibits.cn" target="_blank" rel="noopener">
        <span class="mk">UI Bits</span><span class="hair"></span><span>uibits.cn</span><span>↗</span>
      </a>
      <span>组件来自 UI Bits 组件库</span>
    </div>
  </footer>
</div>

<div class="scrim" id="scrim" aria-hidden="true"></div>

<aside class="drawer" id="drawer" role="dialog" aria-modal="true" aria-label="主导航">
  <div class="drawer-top">
    <span>Menu</span>
    <button class="x" id="close" type="button" aria-label="关闭菜单">
      <svg width="12" height="12" viewBox="0 0 14 14" fill="none" aria-hidden="true">
        <path d="M3 3l8 8M11 3l-8 8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
      </svg>
    </button>
  </div>

  <nav class="menu" id="menu">
    <a href="#" style="--i:0"><span class="n">01</span><span class="t">Work</span>
      <span class="a"><svg width="15" height="15" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M3 13 13 3M13 3H5.5M13 3v7.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span></a>
    <a href="#" style="--i:1"><span class="n">02</span><span class="t">Studio</span>
      <span class="a"><svg width="15" height="15" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M3 13 13 3M13 3H5.5M13 3v7.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span></a>
    <a href="#" style="--i:2"><span class="n">03</span><span class="t">Journal</span>
      <span class="a"><svg width="15" height="15" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M3 13 13 3M13 3H5.5M13 3v7.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span></a>
    <a href="#" style="--i:3"><span class="n">04</span><span class="t">Contact</span>
      <span class="a"><svg width="15" height="15" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M3 13 13 3M13 3H5.5M13 3v7.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span></a>

    <p class="menu-note">2027 年的档期还开着 <b>两个位置</b>,写信比留言快。</p>
  </nav>

  <div class="drawer-foot">
    <a class="mail" href="#">hello@nocturne.studio</a>
    <div class="socials">
      <a href="#" aria-label="Instagram">
        <svg width="13" height="13" viewBox="0 0 16 16" fill="none" aria-hidden="true">
          <rect x="2.4" y="2.4" width="11.2" height="11.2" rx="3.4" stroke="currentColor" stroke-width="1.4"/>
          <circle cx="8" cy="8" r="2.6" stroke="currentColor" stroke-width="1.4"/>
          <circle cx="11.5" cy="4.5" r="0.85" fill="currentColor"/>
        </svg>
      </a>
      <a href="#" aria-label="Vimeo">
        <svg width="13" height="13" viewBox="0 0 16 16" fill="none" aria-hidden="true">
          <path d="M1.8 5.4c1.6-1.3 2.7-1.1 3.3.6.4 1.3.7 3 .9 3.9.3-1.9 1.1-5.4 3.2-5.4 1.5 0 1.9 1.4 1.4 3.3" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/>
          <path d="M11.4 7.6c.6-.1 1.4.2 1.6 1 .3 1.1-.5 2-1.3 2.6-1.6 1.2-3.7 2-5.4 1.6" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/>
        </svg>
      </a>
      <a href="#" aria-label="Email">
        <svg width="13" height="13" viewBox="0 0 16 16" fill="none" aria-hidden="true">
          <rect x="2" y="3.6" width="12" height="8.8" rx="2" stroke="currentColor" stroke-width="1.4"/>
          <path d="M2.6 4.6 8 8.6l5.4-4" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/>
        </svg>
      </a>
    </div>
  </div>
</aside>
<script>
(function () {
  'use strict'
  var CONFIG = { accent: '#a78bfa', depth: 4.5, blur: 2, stagger: 40, credit: true }
  var S = Object.assign({}, CONFIG)

  var body = document.body
  var burger = document.getElementById('burger')
  var close = document.getElementById('close')
  var scrim = document.getElementById('scrim')
  var credit = document.getElementById('credit')

  function apply() {
    document.documentElement.style.setProperty('--accent', S.accent)
    document.documentElement.style.setProperty('--blur', S.blur + 'px')
    document.documentElement.style.setProperty('--stagger', S.stagger + 'ms')
    /* depth 控制抽屉滑入的纵向距离感:越大后退越明显 */
    body.style.setProperty('--depth', S.depth)
    credit.style.display = S.credit ? '' : 'none'
  }

  function open() {
    body.classList.add('is-open')
    burger.setAttribute('aria-expanded', 'true')
  }
  function shut() {
    body.classList.remove('is-open')
    burger.setAttribute('aria-expanded', 'false')
  }

  burger.addEventListener('click', function () {
    body.classList.contains('is-open') ? shut() : open()
  })
  close.addEventListener('click', shut)
  scrim.addEventListener('click', shut)

  document.addEventListener('keydown', function (e) {
    if (e.key === 'Escape' && body.classList.contains('is-open')) shut()
  })

  apply()
})()
</script>

速览

类别
导航
层级
区块
框架
HTML/CSS / React / Vue
复制
0 次

安装

复制对应框架的源码与「样式 CSS」即可,无第三方依赖;可调项集中在开头的 CONFIG。

能力

  • 支持深色
  • 无障碍友好
  • 带动效
  • 响应式

自定义参数

5 项默认

其它参数

尚未归类的可调项
4.5
2
40

使用提示

  1. 先在上方调参数看效果 —— 下方「复制代码」 会跟着你调的值一起变,复制走的就是眼前这一版。
  2. 「React」「Vue」「HTML/CSS」是同一组件的三套实现,按你项目的技术栈挑一套; 「样式 CSS」是它用到的规则(含变量与响应式,只挑了这个组件用到的部分),跟着一起贴。
  3. 代码里的素材是本站绝对地址,换成自己的图只需改 src。

相似组件

按标签重合度推荐,不是运营手配的榜单。

收放导航条 截图

收放导航条

导航 · 组件

色涡 截图

色涡

背景 · 区块

墨蚀 截图

墨蚀

背景 · 区块

网格地平线 截图

网格地平线

背景 · 区块