2.1.1 • Published 3 months ago

@gluedigital/scrollastic v2.1.1

Weekly downloads
18
License
MIT
Repository
-
Last release
3 months ago

scrollastic

A simple library of hooks to deal with scroll events, such as parallax and elements that change on scroll.

Hooks

The following hooks are available:

useAtTop

Returns a boolean indicating whether we are at the top of the scroll or not.

Parameters:

NameTypeDescriptionDefault
scrollableReact Ref / DOMElementThe scroll parent to use for measuringdocumentElement

useAtBottom

Returns a boolean indicating whether we are at the bottom of the scroll or not.

Parameters:

NameTypeDescriptionDefault
scrollableReact Ref / DOMElementThe scroll parent to use for measuringdocumentElement

useScrollBelow

Returns a boolean indicating whether we are below a given scroll threshold or not.

Parameters:

NameTypeDescriptionDefault
pxnumberThe threshold below which the value should be true
scrollableReact Ref / DOMElementThe scroll parent to use for measuringdocumentElement

useScrollBetween

Returns a value between 0 and 1 proportional to the scroll position between the given bounds.

Parameters:

NameTypeDescriptionDefault
startnumberThe start of the scroll range
endnumberThe end of the scroll range
scrollableReact Ref / DOMElementThe scroll parent to use for measuringdocumentElement

useScrollOver

Returns a value between 0 and 1 proportional to the scroll position over a element.
The value will be 0 until the element starts showing, will increase linearly, and reach 1 just as the element leaves the screen.

Parameters:

NameTypeDescriptionDefault
querystringA query string (ie: for querySelector) to pick the target element
scrollableReact Ref / DOMElementThe scroll parent to use for measuringdocumentElement

useScrollSelector

Returns a value depending on which element is scrolled into view.
By default, it returns the ID of the closest element above the window top.

Parameters:

NameTypeDescriptionDefault
querystringA query string (ie: for querySelectorAll) to pick the target elements
optsobjectOther parametersSee below.

Opts:

NameTypeDescriptionDefault
mapperfunctionMaps the current element to the returned value(e) => e.id
boundarystringThe threshold from the screen top at which we measure the current element. Can be in px or vh.0px
fromBottombooleanWhether the boundary should be measured from the screen bottom insteadfalse
scrollableReact Ref / DOMElementThe scroll parent to use for measuringdocumentElement
2.1.1

3 months ago

2.1.0

3 months ago

2.0.1

3 months ago

2.0.0

3 months ago

1.2.7

7 months ago

1.2.6

7 months ago

1.2.5

7 months ago

1.2.4

2 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago