javascript - Bootstrap: scrollspy doesn't work after I've added smooth scrolling -


i'm building site using twitter bootstrap, , got scrollspy work, using below javascript:

$('body').scrollspy({ target: '.navbar' }) 

but stopped working me, after add script enable smooth scrolling:

<script type="text/javascript"> $(document).ready(function() {   // navigation click actions    $('.scroll-link').on('click', function(event){     event.preventdefault();     var sectionid = $(this).attr("data-id");     scrolltoid('#' + sectionid, 750);   });   // scroll top action   $('.scroll-top').on('click', function(event) {     event.preventdefault();     $('html, body').animate({scrolltop:0}, 'slow');        });   // mobile nav toggle   $('.nav-toggle').on('click', function (event) {     event.preventdefault();     $('#bs-example-navbar-collapse-1').toggleclass("open");   }); }); // scroll function function scrolltoid(id, speed){   var offset = 70;   var targetoffset = $(id).offset().top - offset;   var mainnav = $('#bs-example-navbar-collapse-1');   $('html,body').animate({scrolltop:targetoffset}, speed);   if (mainnav.hasclass("open")) {     mainnav.css("height", "1px").removeclass("in").addclass("collapse");     mainnav.removeclass("open");   } } if (typeof console === "undefined") {     console = {         log: function() { }     }; } </script> 

i'm thinking must have added scrollspy in incorrect position. have little knowledge of javascript. if can point me way inserting in correct order/space/line, great!

thanks in advance!

you may want use third party plugin such jquery.localscroll (which relies on jquery.scrollto). provides great smooth scrolling , easy implement. lot easier reimplementing wheel.

https://github.com/flesler/jquery.localscroll


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -