Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

animate-css-grid

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

animate-css-grid

![demo of animate-css-grid in action](./demo/grid.gif)

  • 0.2.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.2K
decreased by-21.17%
Maintainers
1
Weekly downloads
 
Created
Source

Animate CSS Grid

demo of animate-css-grid in action

This small script makes it super easy to make sure your CSS grid transitions gracefully from one state to another. If the content of the grid changes, or if the grid or one of its children is updated with the addition or removal of a class, the grid will automatically transition to its new configuration.

Examples on Codepen

How to use it

Just call the wrapGrid method on your grid container, and optionally provide a config object as a second argument.

ES6 Module:

yarn add animate-css-grid

import { wrapGrid } from animateCSSGrid

const grid = document.querySelector(".grid");

const { unwrapGrid, forceGridAnimation } = wrapGrid(grid, {duration: 500});

// later, to remove transitions
unwrapGrid()

// later, if you are changing grid layout with inline styles and still want the grid to animate
grid.style.width = '200px'
forceGridAnimation()

Or from a script tag:

<script src="https://unpkg.com/animate-css-grid@latest"></script>

<script>
  const grid = document.querySelector(".grid");
  const { unwrapGrid } = animateCSSGrid.wrapGrid(grid, {stagger: true});
</script>

Example optional config object:

{
  // default is false
  stagger: true,
  // default is 250 ms
  duration: 500
  // default is 'Quadratic.InOut'
  easing: 'Sinusoidal.InOut'
}

Available easing functions.

How it works

The script registers a MutationObserver that activates when the grid or one of its immediate children adds or loses a class. It uses the FLIP animation technique to smoothly update the grid, applying a counter transform to the children of each item so that they do not appear distorted while the transition occurs.

Requirements

  1. The updates to the grid will have to come from addition or removal of a class. Currently, inline style updates will not trigger transitions.
  2. If a grid item has children, they should be surrounded by a single container element.

OK:

<!-- grid style applied via a class -->
<div class="some-grid-class-that-changes">
  <!-- a grid item with a single child -->
  <div class="grid-item">
    <div>
      ...child 1
      ...child 2
    </div>
  </div>
<div>

Not going to work:

<!-- grid styles applied inline -->
<div style="[grid styles that change]">
  <!-- a grid item with multiple children -->
  <div class="grid-item">
      ...child 1
      ...child 2
  </div>
<div>

FAQs

Package last updated on 18 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc