SCSS
Scroll Appear contains a SCSS file that exposes a mixin to make it easier to set up the CSS transition used when they appear. The idea behind it is that you should specify the hidden state of the element, and allow it to transition to its default state.
You can import this mixin from the installed Node.js package. The relative path will depend on how your project is organised, but for example:
@import "../../../../node_modules/@cipscis/scroll-appear/scroll-appear";
For example, this CSS sets a hidden element to be faded out and offset to the bottom, so when it transitions to its default state it will fade in and slide up:
.appearing-element {
@include scroll-appear(0.5s, ease-in) {
opacity: 0;
transform: translateY(100px);
}
}
The two arguments of the scroll-appear
mixin are optional, to allow additional control of the duration and easing function of the transition. The default values are 0.3s
and ease-in-out
.
It is important for accessibility that elements aren't given display: none;
or visibility: hidden;
within this mixin. They should still be able to be read by screen readers and receive focus from the keyboard even before Scroll Appear has told them to appear.
Accessibility is built into this mixin by having it respect the prefers-reduced-motion media query. So users who prefer reduced motion will not have these elements animate in for them.
Queues
If an element is configured to have a delay, then the next element should not appear immediately. To accomplish this, elements are added to a queue when they enter the viewport. By default, all elements enter the same queue, but they can also be grouped in two different ways into other queues.
First, if an element has a data-scroll-appear-queue
attribute, then it will enter the same queue as all other elements with the same attribute value.
Second, if an element is an ancestor of an element with the class js-scroll-appear__container
, then it will enter a queue associated with that container.
Otherwise, an element will join the global queue instead.