bootstrap-js组件-滚动监听

注意的点:
1.设置body属性:position: relative;
2.设置body属性:data-target=’#导航条的id’
3.设置body属性:data-offset;来表示内容距顶部的高度范围
4.让导航的a标签来通过id确定应该显示的标题。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery.1.12.4.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/holder.js"></script>
    <title>Bootstrap</title>
</head>
<style type="text/css">
    *{
        font-family: 微软雅黑;
    }
    body{
        position: relative;
        padding-top: 60px;
    }
</style>
<body data-spy='scroll' data-target='#mynavbar' data-offset='200'>
    <div class="container">
        <!-- navbar  begining -->
        <nav class="navbar navbar-inverse navbar-fixed-top" id="mynavbar"> <!-- navbar-default 默认灰色; navbar-inverse :黑灰色-->
            <div class="container">
                    <div class="navbar-header">
                        <!-- 标题 -->
                        <a href="#" class="navbar-brand">Brand</a><!--  也可以换成logo图片 -->
                        <!-- 设置合并后的菜单按钮 -->
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsed_navbar">
                            <span class="sr-only">Toggle navigation</span>
                            <!-- 三条横线 -->
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                    </div>
                    <!-- 可折叠的菜单栏 -->
                    <div id="collapsed_navbar" class="collapse navbar-collapse">
                        <ul class="nav navbar-nav">
                            <li class="active"><a href="#java">java</a></li>
                            <li><a href="#js">javascript</a></li>
                            <li><a href="#bs">bootstrap</a></li>
                            <li><a href="#vue">vue</a></li>
                            <li><a href="#jq">jquery</a></li>
                        </ul>
                    </div>
            </div>
        </nav>
        <div class="panel panel-primary">
            <div class="panel-heading">
                <div class="panel-title">
                    <h2 id="java">java</h2>
                </div>
            </div>
            <div class="panel-body">
                <img src="holder.js/1100x500">
                <p>java is good!</p>
            </div>

            <div class="panel-heading">
                <div class="panel-title">
                    <h2 id="js">javascript</h2>
                </div>
            </div>
            <div class="panel-body">
                <img src="holder.js/1100x500">
                <p>javascript is good!</p>
            </div>
            <div class="panel-heading">
                <div class="panel-title">
                    <h2 id="bs">bootstrap</h2>
                </div>
            </div>
            <div class="panel-body">
                <img src="holder.js/1100x500">
                <p>bootstrap is good!</p>
            </div>
            <div class="panel-heading">
                <div class="panel-title">
                    <h2 id="vue">vue</h2>
                </div>
            </div>
            <div class="panel-body">
                <img src="holder.js/1100x500">
                <p>vue is good!</p>
            </div>
            <div class="panel-heading">
                <div class="panel-title">
                    <h2 id="jq">jquery</h2>
                </div>
            </div>
            <div class="panel-body">
                <img src="holder.js/1100x500">
                <p>jquery is good!</p>
            </div>

        </div>
    </div>
</body>
</html>

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值