• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
向阳光大道勇猛前进吧,了解但不走偏门!
            管理     

原生侧边栏sidebar

创建侧栏导航

 

html:
    <a href="#" class="btn">点我啊</a>
    <div class="sidebar is_hidden">
        原生侧边栏
    </div>


css:
.btn {
    position: fixed;
    right: 100px;
    top: 200px;
    font-size: 30px;
    padding: 3px;
    background-color: #ff102c;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 300px;
    background-color: black;
    text-align: center;
    color: #ff102c;
    font-size: 30px;
    transition: transform 0.5s ease-out;
}
.sidebar.is_hidden {
    transform: translateX(-300px);
}


JavaScript:

const  btn = document.querySelector('.btn');
const sidebar = document.querySelector('.sidebar');

btn.addEventListener('click',function () {
    sidebar.classList.toggle('is_hidden');
})

  

 效果图:

 

 

圣凡无二路,方便有多门。
posted @ 2018-07-09 23:41  优昙陀罗  阅读(297)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3