本文實例為大家分享了bootstrap監聽滾動頭部跟隨滾動的實作方法,供大家參考,具體內容如下
實現案例
<body data-spy="scroll" data-target="#bs-example-navbar-collapse-1"> <div id='menu_wrap'> <div class='menu'> <nav class="navbar navbar-default" role="navigation"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="#" style="font-weight:bold">植被数据录入</a> </div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <!-- <button type="button" class="close" data-dismiss="modal" data-target="#mychart2-zb"><span aria-hidden="true">×</span></button> --> <button type="button" class="btn btn-primary" style="float: right;margin-right: 10px;margin-top: 5px;" data-dismiss="modal" data-target="#mychart2-zb"><span aria-hidden="true">保存</span></button> <button type="button" class="btn btn-primary" style="float: right;margin-right: 10px;margin-top: 5px;" data-dismiss="modal" data-target="#mychart2-zb"><span aria-hidden="true">取消</span></button> </div> </div> </nav> </div> </div> </body>
css控制樣式
導入js.menu{ width:100%; z-index:99; } .menuFixed{ position:fixed; top:0; left:0; } #menu_wrap{ height:50px; width:100%; }