欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

bootstrap实现的自适应页面简单应用示例

程序员文章站 2022-05-12 19:57:19
本文实例讲述了bootstrap实现的自适应页面简单应用。分享给大家供大家参考,具体如下: ...

本文实例讲述了bootstrap实现的自适应页面简单应用。分享给大家供大家参考,具体如下:

<!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='#'>发货结算</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='#'>发货结算</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='#'>联系方式</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>'
            + '<h4 class="list-group-item-heading">' + '大标题' + i + '</h4><br/>'
            + '<p class="list-group-item-text">' + '备注' + i + '<br/>...' + '</p>'
            + '<span class="glyphicon glyphicon-hand-up" aria-hidden="true" style="float:right;"></span>'
            + '<br/>'
            + '</a>';
        }
        str += '</div>';
        $('.content').html(str);
      }
      window.onresize = tnavcontrol;
    })();
  </script>
</body>
</html>

运行效果图:

bootstrap实现的自适应页面简单应用示例

ps:关于bootstrap布局,这里再为大家推荐一款本站的在线可视化布局工具供大家参考使用:

在线bootstrap可视化布局编辑工具:

希望本文所述对大家基于bootstrap的程序设计有所帮助。