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

Value API & Relative Scrolling #80

Open
ganderzz opened this issue Nov 3, 2018 · 0 comments
Open

Value API & Relative Scrolling #80

ganderzz opened this issue Nov 3, 2018 · 0 comments

Comments

@ganderzz
Copy link
Owner

ganderzz commented Nov 3, 2018

Add the ability to scroll by a relative amount (ie. if the window is scrolled down by 100px, we should be able to scroll by -50px to end at 50px scrolled)

This is resolved:
#79


The way this is handled also gives rise to extensible value handlers. An example with the new relative() function:

<ScrollTo>
   {({ scrollTo, relative }) => (
       <button onClick={() => scrollTo({ y: relative(-50) })}>Click Me</button>
   )}
</ScrollTo>

Looking at the implementation of relative(): https://github.com/ganderzz/react-scroll-to/pull/79/files#diff-cfc450c9626bea8788ec583b684d167b

Users could add their own functions:

export function addTen(input) {
  if (!input || typeof input !== "number") {
    console.warn(
      `Invalid input (${input}) given to relative(). Is this a number?`
    );
  }

   return function(element, isHorizontal) {
    if (!element || !isHorizontal) {
      return input;
    }

     return input + 10;
  };
}
<ScrollTo>
   {({ scrollTo, relative }) => (
       <button onClick={() => scrollTo({ y: addTen(20) })}>Click Me</button>
   )}
</ScrollTo>

^ Will scroll down by 30px

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

No branches or pull requests

1 participant