awesome-scroll
v0.1.7
Published
A simple and fast container to monitor elements as you scroll
Downloads
9
Readme
awesome-scroll
A simple and fast container to monitor elements as you scroll https://stephenkingsley.github.io/stress.html
BASIC USAGE
first
npm install awesome-scroll --save
and in your code
import awesomeScroll from "awesome-scroll";
const scrollElement = document.getElementById("scrollElement");
const watcherElement = awesomeScroll.create(scrollElement);
const addClass = () => {
if (!this.isInViewport) {
return;
} else if (this.isFullyInViewport) {
this.watchItem.style.backgroundColor = '#fcc';
} else if (this.isAboveViewport) {
this.watchItem.style.backgroundColor = '#ccf';
} else if (this.isBelowViewport) {
this.watchItem.style.backgroundColor = '#ffc';
}
}
watcherElement.stateChange(addClass);
DEMO
👇 localhost demo
git clone https://github.com/stephenkingsley/awesome-scroll.git
cd awesome-scroll
npm i
npm run dev