GithubHelp home page GithubHelp logo

lukecarlthompson / iocascade.js Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 779 KB

Intersection observer powered scroll listener staggers reveal effects by default

Home Page: https://lukecarlthompson.github.io/IoCascade.js/.

License: MIT License

HTML 20.65% JavaScript 53.78% CSS 25.57%
scroll animation javascript

iocascade.js's Introduction

IoCascade.js ๐Ÿ’ƒ๐Ÿ•บ

A lil' js lib that detects when elements appear in view and staggers the animations

Example page at https://lukecarlthompson.github.io/IoCascade.js/

Use like this (defaults shown).

const cascade = new IoCascade({
  selector: '[data-io]',
  classToAdd: 'io-in',
  delay: 100,
  threshold: 1,
  rootMargin: '0px 100px 0px 100px',
  root: null,
});

IoCascade detects the first time an element with the data-io property on it enters the viewport and adds it to a queue.

After a default delay of 100ms it then apply's a class of io-in to the item and then checks for the next item in the queue. If there is one there (another item has scrolled into view before the animation started) it will wait for the next delay and repeat.

If the element has a data-delay="500" property set then it will use this number in milliseconds for the delay for that item instead of the default.

This way we can quickly set up staggered delays for multiple items that are on the screen at once with a minimum of fine tuning.

IoCascade.js can also trigger child elements based on a parent entering the viewport. The parent should have a data-io attribute as normal, but all the children should have data-io="child" property set. This way the child elements animations will not be triggered until the parent has scrolled into view. Once the parent is in view all the child elements will be animated in sequence.

Dev setup

It uses gulp, scss, browserSync, Rollup and buble.

Folder structure

_src/ - is where you work
docs/ - is where the browserSync server runs from
dist/ - contains the processed js files

Get started

  1. npm install - install dependencies
  2. npm run dev - spins up the dev server
  3. npm run build - transpiles and builds final js files in dist/ folder
  4. npm run clean - deletes the docs and dist folders

iocascade.js's People

Contributors

lukecarlthompson avatar

Watchers

James Cloos avatar Jesse Yuen avatar  avatar

iocascade.js's Issues

Callback functions

Have the option of passing in a callback function that fires when the element scrolls in to view and when the timer runs out for each item.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.