Keyscroll is a lightweight library that makes fancy scroll animations a breeze.
Animate your CSS keyframes by scrolling through the page. This library can work independently or with a smooth scrolling library of your choice.
-
Install:
npm install keyscroll keyscroll-ng --save
-
Create a keyframe animation. For example (in styles.scss):
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
-
Add the keyscroll module:
imports: [ KeyscrollNgModule ],
-
Tell keyscroll how it should monitor scroll events. The easiest way is as follows:
import { keyscroller } from 'keyscroll'; keyscroller.initializeFromDomEvents();
If you are using a smooth scrolling library, you may want to bind to a callback thrown by this library. In that case, check this section in the docs.
-
Use the keyscroll directive on whichever element you would like to animate:
<div keyscroll="fade"> </div>
When this element is at the top of the screen, it will be invisible, at the bottom, it will be fully visible. To learn what else you can do check the
README.md
thekeyscroll-ng
package, or the Angular docs source code.
-
Install:
npm install keyscroll --save
. (Todo: cdnjs). -
Create a keyframe animation, in your styles.css, for example:
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
-
Initialize it, and attach it to all elements you'd like to animate:
import {elementAnimate, keyscroller} from "keyscroll"; window.onload = () => { keyscroller.initializeFromDomEvents(); const myElement = document.querySelector('[data-fade-me]'); elementAnimate.attachAnimation(myElement, 'fade', { animationTiming: 'linear', animationStart: 0, animationEnd: 1 }); }
For React, a Stackblitz with a simple example can be found here Stackblitz. A React Wrapper will be built into this project soon. In the meantime, React usage is documented here.
Name | Version | Bundle Size |
---|---|---|
keyscroll | 0.1.1 | |
keyscroll-ng | 0.1.1 | |
keyscroll-docs | 0.1.0 | 248K |
Once you have cloned the project, run: npm install
to install all dependencies. A post installation command will then install
remaining dependencies across all projects in the repository.
To start a dev build, run npm start
. This will start the docs, and watcher on the library locally.
Modules are resolved in package.json via relative paths:
"keyscroll": "file:../keyscroll"
. This means that the docs will always point to the latest changes you make in the keyscroll package.
The project can be built for production by running:
$ npm run build
The command will build all packages. The build can be found in the ./dist
folder of the project, ready to be deployed to github pages.
To serve the built project locally, use:
$ npm run local-server
Once hosted, this will allow you to try out both the Angular Demo, as well as the Vanilla JS demo locally.
To test all packages in the project run:
$ npm run test
.
Due to locally resolved dependencies, remember to build before running the test command.
To lint all packages run:
$ npm run lint