How to add smooth scrolling to Bootstrap's scroll spy function

前端 未结 8 1041
死守一世寂寞
死守一世寂寞 2020-11-30 17:30

I\'ve been trying to add a smooth scrolling function to my site for a while now but can\'t seem to get it to work.

Here is my HTML code relating to my navigation:<

8条回答
  •  -上瘾入骨i
    2020-11-30 17:50

    If you download the jquery easing plugin (check it out),then you just have to add this to your main.js file:

    $('a.smooth-scroll').on('click', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top + 20
        }, 1500, 'easeInOutExpo');
        event.preventDefault();
    });
    

    and also dont forget to add the smooth-scroll class to your a tags like this:

     
  • About Us
提交回复
热议问题