Topic: Updating smooth-scroll to support offset.

Robert McIntosh pro asked 5 years ago

Hello, thought I would drop another suggestion for your amazing work. I use the smooth-scroll option for my single page website and it has annoyed me that the fixed navbar always overlayed the content after scrolling to the content. I also didn't like the idea of adding a 60px margin to the top of each section. So I updated the smooth-scroll portion to allow you to define an offset. Here is the updated code below, use it or not is up to you.
$(".smooth-scroll").on('click', 'a', function (event) {
    var elAttr = $(this).attr('href'),
    	offset = ($(this).data('offset') ? $(this).data('offset') : 0);
        scrollTop: $(elAttr).offset().top + offset
    }, 700);

As always your post is really helpful! Thanks again for your support for MDB ;) We'll take a look at this ;)

Please insert min. 20 characters.


Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.


Specification of the issue

  • User: Pro
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No