溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

bootstrap實現(xiàn)的自適應頁面簡單應用示例

發(fā)布時間:2020-09-08 18:51:59 來源:腳本之家 閱讀:198 作者:繼續(xù)去踢波 欄目:web開發(fā)

本文實例講述了bootstrap實現(xiàn)的自適應頁面簡單應用。分享給大家供大家參考,具體如下:

<!DOCTYPE html>
<html>
<head>
  <meta charset='utf-8'>
  <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  <meta name='viewport' content='width=device-width, initial-scale=1'>
  <link rel='stylesheet' href='http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css'>
  <style>
    .tNav{
      margin-top: 10px;
      border-bottom-style: none;
    }
    .bNav{
      text-align: center;
      height: 50px;
      line-height: 50px;
      font-size: 20px;
    }
    #btnNavList{
      font-size: 20px;
      position: absolute;
      top: 15px;
      right: 20px;
    }
    #btnNavList:hover{
      cursor: pointer;
    }
    .bNav:hover{
      background: #EED2EE;
      cursor: pointer;
    }
    #btnNavList,
    #normalTNav,
    #btnNavList-nav,
    #btnMess-nav,
    #btnMore-nav{
      display: none;
    }
    #btnNavList-nav,
    #btnMess-nav,
    #btnMore-nav{
      text-align: center;
      background: #FFF0F5;
      position: fixed;
      right: 0;
      width: 100%;
      filter:alpha(opacity=80);
      -moz-opacity: 0.8;
      -khtml-opacity: 0.8;
      opacity: 0.8;
    }
    #btnNavList-nav{
      top: 50px;
    }
    #btnMess-nav,
    #btnMore-nav{
      bottom: 50px;
    }
    #btnNavList-nav a,
    #btnMess-nav a,
    #btnMore-nav a{
      display: block;
      text-decoration: none;
      height: 50px;
      line-height: 50px;
    }
    #btnNavList-nav a{
      border-bottom: 1px solid #EED2EE;
    }
    #btnMess-nav a,
    #btnMore-nav a{
      border-top: 1px solid #EED2EE;
    }
    #btnNavList-nav a:hover,
    #btnMess-nav a:hover,
    #btnMore-nav a:hover{
      background: #EED2EE;
      cursor: pointer;
    }
    .content{
      margin: 70px 0;
    }
  </style>
</head>
<body>
  <nav class='navbar navbar-default navbar-fixed-top'>
    <div class='container-fluid'>
      <div class='navbar-header tNavLogo'>
        <span class='glyphicon glyphicon-th-list' aria-hidden='true' id='btnNavList'></span>
        <a class='navbar-brand' href='#'>Logo</a>
      </div>
      <ul class='nav nav-tabs tNav' id='normalTNav'>
        <li role='presentation'><a href='#'>基礎信息</a></li>
        <li role='presentation'><a href='#'>基地訂單</a></li>
        <li role='presentation'><a href='#'>總部訂單</a></li>
        <li role='presentation'><a href='#'>發(fā)貨結算</a></li>
        <li role='presentation'><a href='#'>生產物流</a></li>
        <li role='presentation'><a href='#'>庫存查詢</a></li>
      </ul>
    </div>
  </nav>
  <div class='content'></div>
  <nav class='navbar navbar-default navbar-fixed-bottom'>
    <div class='container-fluid'>
      <div class='row'>
        <div class='col-xs-3 bNav' id='btnHome'>
          <span class='glyphicon glyphicon-home' aria-hidden='true'></span>
        </div>
        <div class='col-xs-3 bNav' id='btnUser'>
          <span class='glyphicon glyphicon-user' aria-hidden='true'></span>
        </div>
        <div class='col-xs-3 bNav' id='btnMess'>
          <span class='glyphicon glyphicon-comment' aria-hidden='true'></span>
        </div>
        <div class='col-xs-3 bNav' id='btnMore'>
          <span class='glyphicon glyphicon-option-horizontal' aria-hidden='true'></span>
        </div>
      </div>
    </div>
  </nav>
  <div id='btnNavList-nav'>
    <div><a href='#'>基礎信息</a></div>
    <div><a href='#'>基地訂單</a></div>
    <div><a href='#'>總部訂單</a></div>
    <div><a href='#'>發(fā)貨結算</a></div>
    <div><a href='#'>生產物流</a></div>
    <div><a href='#'>庫存查詢</a></div>
  </div>
  <div id='btnMess-nav'>
    <div><a href='#'>我的消息1</a></div>
    <div><a href='#'>我的消息2</a></div>
    <div><a href='#'>我的消息3</a></div>
  </div>
  <div id='btnMore-nav'>
    <div><a href='#'>當前版本</a></div>
    <div><a href='#'>意見反饋</a></div>
    <div><a href='#'>聯(lián)系方式</a></div>
    <div><a href='#'>關于</a></div>
  </div>
  <script src='http://cdn.bootcss.com/zepto/1.1.4/zepto.min.js'></script>
  <script>
    (function(){
      function SHOW(obj){
        obj.css('display','block');
      }
      function HIDE(obj){
        obj.css('display','none');
      }
      function TOGGLE(e){
        var obj = $(e);
        if(obj.css('display') === 'none'){
          obj.css('display', 'block');
        }
        else if(obj.css('display') === 'block'){
          obj.css('display', 'none');
        }
      }
      function tNavControl(){
        var w = window.document.body.offsetWidth;
        var objBtn = $('#btnNavList');
        var objNor = $('#normalTNav');
        var objUnNor = $('#btnNavList-nav');
        if(w <= 768){//小屏幕
          SHOW(objBtn);
          //SHOW(objUnNor);
          HIDE(objNor)
        }
        else{
          HIDE(objBtn);
          HIDE(objUnNor);
          SHOW(objNor);
        }
      }
      $('#btnNavList').on('click', function(){
        HIDE($('#btnMess-nav'));
        HIDE($('#btnMore-nav'));
        TOGGLE('#btnNavList-nav');
        return false;
      })
      $('#btnMess').on('click', function(){
        HIDE($('#btnNavList-nav'));
        HIDE($('#btnMore-nav'));
        TOGGLE('#btnMess-nav');
        return false;
      })
      $('#btnMore').on('click', function(){
        HIDE($('#btnNavList-nav'));
        HIDE($('#btnMess-nav'));
        TOGGLE('#btnMore-nav');
        return false;
      })
      $('body').on('click', function(){
        HIDE($('#btnNavList-nav'));
        HIDE($('#btnMess-nav'));
        HIDE($('#btnMore-nav'));
      })
      window.onload = function(){
        tNavControl();
        var str = '<div class="list-group">';
        for(var i=0; i<=100; i++){
          str +=
             '<a class="list-group-item" href="#" rel="external nofollow" >'
            + '<span class="badge">' + i + '</span>'
            + '<h5 class="list-group-item-heading">' + '大標題' + i + '</h5><br/>'
            + '<p class="list-group-item-text">' + '備注' + i + '<br/>...' + '</p>'
            + '<span class="glyphicon glyphicon-hand-up" aria-hidden="true" ></span>'
            + '<br/>'
            + '</a>';
        }
        str += '</div>';
        $('.content').html(str);
      }
      window.onresize = tNavControl;
    })();
  </script>
</body>
</html>

運行效果圖:

bootstrap實現(xiàn)的自適應頁面簡單應用示例

PS:關于bootstrap布局,這里再為大家推薦一款本站的在線可視化布局工具供大家參考使用:

在線bootstrap可視化布局編輯工具:
http://tools.jb51.net/aideddesign/layoutit

希望本文所述對大家基于bootstrap的程序設計有所幫助。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI