javascript - Bootstrap Scroll Spy not working.Shows only the home state active but doesnt change to other states when scrolled down -
this html , css.please me scrollspy dont know problem .if possible let me know code have written solve problem
my html:
<nav class="navbar navbar-default center navbar-fixed-top" id="navbar"> <button class="navbar-toggler hidden-sm-up"type="button" data-toggle="collapse" data-target="#excollapsingnavbar2">☰</button> <div class="collapse navbar-toggleable-xs" id="excollapsingnavbar2"> <a class="navbar-brand" href="#"></a> <div class="navbar-inner"> <ul class="nav navbar-nav"> <li class="nav-item active"> <a class="nav-link" data-target="#jumbotron">home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" data-target="#about">about</a> </li> <li class="nav-item"> <a class="nav-link" data-target="#skills">skills</a> </li> <li class="nav-item"> <a class="nav-link" href="#contact">contact</a> </li> </ul> </div> </div> </nav> <div class=" jumbotron" id="jumbotron"></div> <div id="about"></div> <div id="skills"></div> <div id="contact"></div>
my css
and divs of 750px in heights
body { background: none; position: relative; margin: 0; padding: 0; font-family: 'droid serif', georgia, times, serif; } /* --------------------------------------------navbar css--------------------------------------------------- */ .navbar-default { background-color: #610b0b ; border-radius:0px; } .navbar-default .navbar-nav > li > { color: white; font-size: 15px; font-family: 'droid serif', georgia, times, serif; letter-spacing: 1px; margin: 3px 10px -3px 10px; border: 2px solid transparent; padding: 8px; } .navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { border: 2px solid white; border-radius: 5px; color: white; padding: 8px; } .navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:hover, .navbar-default .navbar-nav > .active > a:focus { border: 2px solid white; border-radius: 5px; color: #555; background-color: #e7e7e7; }
there couple of things wrong.
first, 3 of nav-link
anchors have data-target=
when should have href=
second, need set data-target=
<body>
of navbar. allows javascript find target scrollspy:
<body data-target="#navbar">
and third, if haven't, need call scrollspy via javascript:
$('body').scrollspy({ target: '#navbar' })
here codepen working example:
Comments
Post a Comment