RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案

一个导航栏的布局,用了两个导航菜单,一个是pc端的,一个是手机端,利用bootstrap响应式使用工具类visible-xs visible-sm来实现pc端隐藏切换按钮; visible-lg visible-md 实现了pc端显示导航栏;visible-xs visible-sm实现手机端显示手机导航栏。
bootstrap响应式工具类详见:https://www.runoob.com/bootstrap/bootstrap-responsive-utilities.html

css实现布局和侧滑效果(侧滑的关键css3属性transform、transition)

代码不多,仅仅10行 

  * {margin:0;padding:0;}
     #mobile-menu {position:fixed;top:0;left:0;width:220px;height:100%;background-color:#373737;z-index:9999;}
     a:hover ,a:focus{text-decoration:none}
    .mobile-nav ul li a {color:gray;display:block;padding:1em 5%;  border-top:1px solid #4f4f4f;border-bottom:1px solid #292929;transition:all 0.2s ease-out;cursor:pointer;#mobile-menu {position:fixed;top:0;left:0;width:220px;height:100%;background-color:#373737;z-index:9999;transition:all 0.3s ease-in;}}
    .mobile-nav ul li a:hover {background-color: #23A1F6;color: #ffffff;}
    .show-nav {transform:translateX(0);}
    .hide-nav {transform:translateX(-220px);} /*侧滑关键*/
    .mobile-nav-taggle {height:35px;line-height:35px;width:35px;background-color:#23A1F6;color:#ffffff;display:inline-block;text-align:center;cursor:pointer}
    .nav.avbar-inverse{position:relative;}
    .nav-btn {position:absolute;right:20px;top:20px;}

要值得注意的是css3的两个属性:

transform:旋转div,支持元素2D或3D旋转,属性值translateX(X)就是在X轴上移动Xpx的距离

http://www.w3school.com.cn/cssref/pr_transform.asp

而侧滑的动画效果是使用transition属性,设置属性的过渡动画的效果,语法

transition: property duration timing-function delay;

http://www.w3school.com.cn/cssref/pr_transition.asp

单击事件切换侧滑

 $("#mobile-nav-taggle").click(function () {
      var mobileMenu = $("#mobile-menu");
      if (mobileMenu.hasClass("show-nav")) {
        setTimeout(function () {
          mobileMenu.addClass("hide-nav").removeClass("show-nav");
        }, 100)
      }
      else {
        setTimeout(function (){
          mobileMenu.addClass("show-nav").removeClass("hide-nav");
        }, 100)
      }
    })

看完上述内容,你们掌握怎么在bootstrap自定义样式实现侧边导航栏功能的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


网站标题:怎么在bootstrap自定义样式实现侧边导航栏功能
分享路径:http://jxjierui.cn/article/pdcipd.html
Top