国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

bootstrap自定義樣式之bootstrap實(shí)現(xiàn)側(cè)邊導(dǎo)航欄功能

2019-11-19 12:58:51
字體:
供稿:網(wǎng)友

bootstrap自帶的響應(yīng)式導(dǎo)航欄是向下滑動(dòng)的,有時(shí)滿足不了個(gè)性化的需求,需要做一個(gè)類似于android drawerLayout 側(cè)滑的菜單,這就是我要實(shí)現(xiàn)的bootstrap自定義側(cè)滑菜單,參考了很多官網(wǎng)的側(cè)滑,實(shí)現(xiàn)方法各有不同,優(yōu)缺點(diǎn)也十分明顯,有的官網(wǎng)首頁(yè)為了僅僅實(shí)現(xiàn)一個(gè)側(cè)滑的效果,用了owl.carousel滑屏的插件,個(gè)人覺得小題大做了。這個(gè)bootstrap側(cè)滑菜單更專業(yè)的名字叫做手機(jī)導(dǎo)航欄。我也比較這個(gè)名字,更符合bootstrap的特性。所以我這篇文章介紹的更容易的一種做法,新手更容易接受。

bootstrap側(cè)邊導(dǎo)航欄實(shí)現(xiàn)原理

1.側(cè)滑欄使用定位fixed
2.使用bootstrap響應(yīng)式使用工具類 visible-sm visible-xs hidden-xs hidden-sm等對(duì)不同屏幕適配
3.側(cè)滑欄的側(cè)滑效果不使用jquery方法來實(shí)現(xiàn),使用的是css3 transforms屬性進(jìn)行div的移動(dòng),側(cè)滑的動(dòng)畫效果使用的是css屬性transition
4.缺點(diǎn):使用兩套菜單,一套是pc端屏幕顯示的菜單,一套是移動(dòng)端顯示的手機(jī)導(dǎo)航菜單,這個(gè)缺點(diǎn)比較明顯,生成無(wú)關(guān)的標(biāo)簽,優(yōu)點(diǎn)代碼少,簡(jiǎn)單容易接受

效果圖

bootstrap側(cè)邊導(dǎo)航欄 

這里寫圖片描述

bootstrap側(cè)邊導(dǎo)航欄

bootstrap導(dǎo)航欄布局  <!--手機(jī)導(dǎo)航欄-->  <div id="mobile-menu" class="mobile-nav visible-xs visible-sm">    <ul>      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁(yè)</a></li>      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Java</a></li>      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >SVN</a></li>      <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >iOS</a></li>    </ul>  </div>  <!--pc導(dǎo)航欄-->  <nav class="navbar-inverse visible-lg visible-md" role="navigation">    <div class="container">      <div class="navbar-header">        <a class="navbar-brand" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >菜鳥教程</a>      </div>      <div>        <ul class="nav navbar-nav">          <li class="active"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >iOS</a></li>          <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >SVN</a></li>          <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="dropdown-toggle" data-toggle="dropdown">Java</a></li>        </ul>      </div>    </div>  </nav>  <!--手機(jī)導(dǎo)航欄側(cè)滑-->  <div class="nav-btn visible-xs visible-sm">    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="mobile-nav-taggle" id="mobile-nav-taggle">      <span class="glyphicon glyphicon-align-justify"></span>    </a>  </div>

一個(gè)導(dǎo)航欄的布局,用了兩個(gè)導(dǎo)航菜單,一個(gè)是pc端的,一個(gè)是手機(jī)端,利用bootstrap響應(yīng)式使用工具類visible-xs visible-sm來實(shí)現(xiàn)pc端隱藏切換按鈕; visible-lg visible-md 實(shí)現(xiàn)了pc端顯示導(dǎo)航欄;visible-xs visible-sm實(shí)現(xiàn)手機(jī)端顯示手機(jī)導(dǎo)航欄。
bootstrap響應(yīng)式工具類詳見:https://www.runoob.com/bootstrap/bootstrap-responsive-utilities.html

css實(shí)現(xiàn)布局和側(cè)滑效果(側(cè)滑的關(guān)鍵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);} /*側(cè)滑關(guān)鍵*/    .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的兩個(gè)屬性:

transform:旋轉(zhuǎn)div,支持元素2D或3D旋轉(zhuǎn),屬性值translateX(X)就是在X軸上移動(dòng)Xpx的距離

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

而側(cè)滑的動(dòng)畫效果是使用transition屬性,設(shè)置屬性的過渡動(dòng)畫的效果,語(yǔ)法

transition: property duration timing-function delay;

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

單擊事件切換側(cè)滑

 $("#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)      }    })

總結(jié)

不推薦用兩個(gè)菜單導(dǎo)航欄,缺點(diǎn)很明顯,為了實(shí)現(xiàn)效果而已,不要介意,其實(shí)用一個(gè)菜單導(dǎo)航欄也是可以實(shí)現(xiàn),試試media 完全可以實(shí)現(xiàn)。

代碼下載地址: 點(diǎn)擊此處下載

以上所述是小編給大家介紹的bootstrap自定義樣式之bootstrap實(shí)現(xiàn)側(cè)邊導(dǎo)航欄功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 湘潭县| 两当县| 保山市| 宣武区| 滦南县| 缙云县| 五指山市| 阳春市| 岑巩县| 榆树市| 芦溪县| 穆棱市| 灵石县| 罗城| 邵阳县| 济南市| 恭城| 五台县| 乐清市| 彭州市| 科技| 霍邱县| 紫阳县| 富蕴县| 安阳县| 荔浦县| 镇雄县| 宁都县| 宁海县| 河东区| 九龙坡区| 恩施市| 桐乡市| 石河子市| 泾川县| 辽阳县| 潍坊市| 丹凤县| 河北省| 项城市| 临江市|