1.0.3 • Published 3 years ago

beautify-scroll v1.0.3

Weekly downloads
58
License
ISC
Repository
github
Last release
3 years ago

License: MIT

Beautify Scroll - Animate elements on scroll

A simple library that allows you to animate elements when they enter the viewport

alt text

Installation

npm i beautify-scroll --save-dev

Usage

Basic

BeautifyScroll.init({
    selector: '.items'
})

By default, this will wrap items in a <span> and then watch viewport for intersecting elements.

When an element leaves the viewport a class is added to it, it's this one that will be used for our transition, by default it's .scroll-animated.

You are free to define the transition used, here is the demo transformations :

.scroll-animated {
    opacity: 0;
    transform: translate3d(0, 50%, 0);
}

Don't forget to add a transition for your items, here is the demo transition :

.items {
    transition: all .5s linear;
}

Advanced

const bs = BeautifyScroll.init({
    selector: '.items'
})

Listen to ready event :

bs.on('ready', () => {
    doSomething()
})

Reset the observer when adding new items to the container, useful to refresh transitions :

bs.on('update', () => bs.reset())

Options

OptionTypeDefautInformations
selectorCSS Classnullex: .items
margininteger0Observer margin
wrapItemsbooleantruetrue due to an issue during some transitions
callbackfnnullCallback when items are intersecting viewport
thresholdinteger0IntersectionObserver threshold
animationClassNamestringscroll-animatedTransition class name

Methods

init({opts}) Initialize an instance with options

reset() Reset observer to refresh transitions

Events

ready instance is ready

update items added to parent container

Live

I use this package on one of my websites, if you want to see a live version.

A demo is also available in the package : npm run watch at http://localhost:8080/demo/

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago