angular-scrollspy icon indicating copy to clipboard operation
angular-scrollspy copied to clipboard

Is there anyway to provide offset?

Open raviayadav opened this issue 7 years ago • 9 comments

Hi. great work. Is there any way we can add some top offset to the divs being monitored?

raviayadav avatar Nov 17 '17 09:11 raviayadav

@raviayadav unfortunately not at the moment but it is something we can look to add in the future. I will try and look into this when I get a chance.

edoparearyee avatar Nov 17 '17 15:11 edoparearyee

okay, thanks

raviayadav avatar Nov 22 '17 05:11 raviayadav

I'm going to reopen this issue until we add this feature so we don't forget it.

edoparearyee avatar Nov 22 '17 10:11 edoparearyee

+1

Nexeuz avatar Jul 12 '18 04:07 Nexeuz

You can provide an offset by adding the following:

  :target:before {
    content:"";
    display:block;
    height:64px; /* fixed header height*/
    margin:-64px 0 0; /* negative fixed header height */
  }

https://stackoverflow.com/a/28824157

EDIT: Ahh I see, the above will fix the issue of it scrolling to the wrong location but it does not address the issue of the scrollspy not properly monitoring the element. This feature would be very helpful. +1!

Asheq096 avatar Jul 16 '18 04:07 Asheq096

This would be an excellent feature. +1. Currently when scrolling down to the content, I'm always left on the section above in my "table of contents"

burzum619 avatar Jul 17 '18 23:07 burzum619

If you see there is an error in the library because you need one more scroll to active the class. However I found a solution.

To the div where you want to go: Add a class called offset then in your css: .offset:before { display: block; content: " "; margin-top: 5px; /* Give negative margin of your fixed element */
visibility: hidden; }

You should play with the margin top with other values to get a specific result

tratohecho3 avatar Aug 28 '18 15:08 tratohecho3

@tratohecho3, could you post an example?

rafaneri avatar Sep 04 '18 23:09 rafaneri

Another way to offset the <sn-scroll-spy-section> component is to wrap it in a custom component and position absolute the <sn-scroll-spy-section> N pixels upwards to force the offset. That way the scroll spy active class will be added N pixels before it arrives at the top of your screen:

Wrapper component template:

<sn-scroll-spy-section 
    class="scrollspy-trigger"
    ...
</sn-scroll-spy-section>
<ng-content></ng-content>

Wrapper component scss:

:host {
  display: block;
  position: relative;
}

.scrollspy-trigger {
  position: absolute;
  top: -60px;
  bottom: -60px;
  left: 0px;
  right: 0px;
  pointer-events: none;
}

maxmumford avatar Oct 26 '18 15:10 maxmumford