0.1.0 • Published 5 years ago

react-use-sync-scroll v0.1.0

Weekly downloads
889
License
MIT
Repository
github
Last release
5 years ago

useSyncScroll

A custom React hook for synchronized, proportional, horizontal and/or vertical DOM element scrolling.

Install

With npm:

npm install react-use-sync-scroll

Or with Yarn:

yarn add react-use-sync-scroll

Or in a browser:

<script scr="https://unpkg.com/react-use-sync-scroll/dist/index.js"></script>

Use

The hook accepts two arguments:

  • The number of elements to synchronize
  • An options object to define whether to synchronize horizontal or vertical scrolling (both default to false)

It returns an array of refs to assign to your elements. For example:

import useSyncScroll from 'react-use-sync-scroll';

function myComponent() {
  const refs = useSyncScroll(3, { vertical: true, horizontal: false });

  return (
    <div>
      <div ref={refs[0]}>...</div>
      <div ref={refs[1]}>...</div>
      <div ref={refs[2]}>...</div>
    </div>
  );
}

You can see a working example on this Codesandbox.

License

MIT

Author

Angelos Orfanakos

0.2.0-rc2

5 years ago

0.2.0-rc1

5 years ago

0.1.0

5 years ago

0.1.0-rc2

5 years ago

0.1.0-rc1

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.4-rc2

5 years ago

0.0.4-rc1

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.2-rc3

5 years ago

0.0.2-rc2

5 years ago

0.0.2-rc1

5 years ago

0.0.1

5 years ago