baptistebriel / smooth-scrolling

smooth scrolling and parallax effects on scroll
MIT License
612 stars 75 forks source link

Smooth.scrollTo and Anchor links #89

Closed 23d1 closed 3 years ago

23d1 commented 6 years ago

I have a two-part question. Is there a way to use scrollTo (or any other way) to simply snap to (0,0), without animation and easing? Is there also a way to use #anchorlinks to scroll to, with/without easing?

baptistebriel commented 6 years ago

You should be able to snap to a scroll value using:

const value = 400 // whatever value you need
this.vars.current = this.vars.target = value

If you want to use anchor links, you'll have to know the top position of the section you want to scrollTo. You can get that value on click for example by calling element.getBoundingClientRect()

Let me know if that works!