Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there anyway to provide offset? #1

Open
raviayadav opened this issue Nov 17, 2017 · 9 comments
Open

Is there anyway to provide offset? #1

raviayadav opened this issue Nov 17, 2017 · 9 comments

Comments

@raviayadav
Copy link

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

@edoparearyee
Copy link

@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.

@raviayadav
Copy link
Author

okay, thanks

@edoparearyee
Copy link

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

@edoparearyee edoparearyee reopened this Nov 22, 2017
@Nexeuz
Copy link

Nexeuz commented Jul 12, 2018

+1

@Asheq096
Copy link

Asheq096 commented Jul 16, 2018

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!

@burzum619
Copy link

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"

@tratohecho3
Copy link

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

@rafaneri
Copy link

rafaneri commented Sep 4, 2018

@tratohecho3, could you post an example?

@maxmumford
Copy link
Contributor

maxmumford commented Oct 26, 2018

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants