Topic: Scrollspy offset nor working

Christen priority asked 1 year ago


Expected behavior when navigating to a section in the scroll spy, which has an offset declared, the view jumps to the section with an offset.

Actual behavior offset is ignored.

Use case The page has a fixed top header, so all content is shifted by a top-margin. When navigating to the section without an offset, the first part of the section is hidden behind the header.

Resources (screenshots, code snippets etc.) code snippet: https://mdbootstrap.com/snippets/standard/christen/4241960


Michał Duszak staff commented 1 year ago

Thank you for your feedback. I have added this issue to our todo list.


Rafał Seifert staff answered 1 year ago


The purpose of scrollspy's offset attribute is to specify the number of pixels to offset from top when calculating the position of scroll. This calculation is used to set proper active state when you reach certain section, not to actually influence the scroll itself. This is useful when you feel that the links inside the navbar change the active state too soon or too early when jumping to the scrollable elements.

We are not going to change the scrollspy's offset attribute as it is working correctly now.

In order to achieve the desired behavior you can try using our smooth scroll method in combination with scrollspy. Here is example snippet with offset set on 3rd link. https://mdbootstrap.com/snippets/angular/r-seifert/4530141



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Answered

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Angular
  • MDB Version: MDB5 2.3.0
  • Device: laptop
  • Browser: firefox and chrome
  • OS: windows 11
  • Provided sample code: No
  • Provided link: Yes