ランキングに戻る

aholachek/animate-css-grid

TypeScript

Painless transitions for CSS Grid

css-gridtransitionsanimations
スター成長
スター
1.4k
フォーク
71
週間成長
Issue
25
5001k
2018年3月2020年12月2023年10月2026年7月
成果物npmnpm install animate-css-grid
README

Animate CSS Grid

Performantly animate all CSS grid properties, including:

grid-column and grid-row

grid-column and grid-row

grid-template-columns

grid-template-columns

grid-gap

grid-gap

Fork Photo Grid Example on CodeSandbox

Why use animate-css-grid?

This library uses transforms to transition between different layout states, which means, in comparison to pure CSS animations, it offers:

  • better performance
  • more flexibility in terms of what properties can be animated
  • more configurable animations (easing options, staggers)

Want to have a look for yourself? Feel free to check out this Mondrian animated with CSS keyframes and compare it with the same UI animated with animate-css-grid.

How to use it

Just call the wrapGrid method on your grid container, and optionally provide a config object as a second argument. If the grid is removed from the page, the animations will automatically be cleaned up as well.

yarn add animate-css-grid or npm install animate-css-grid

import { wrapGrid } from 'animate-css-grid'

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

Or from a script tag:

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

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

Optional config object:

{
  // int: default is 0 ms
  stagger: 100,
  // int: default is 250 ms
  duration: 500,
  // string: default is 'easeInOut'
  easing: 'backInOut',
  // function: called with list of elements about to animate
  onStart: (animatingElementList)=> {},
  // function: called with list of elements that just finished animating
  // cancelled animations will not trigger onEnd
  onEnd: (animatingElementList)=> {}
}

Available easing functions:

  • 'linear'
  • 'easeIn' / 'easeOut' / 'easeInOut'
  • 'circIn' / 'circOut' / 'circInOut'
  • 'backIn' / 'backOut' / 'backInOut'
  • 'anticipate'

Learn more about available easing functions here.

Two functions are returned by the wrapGrid call that you probably won't need to use:

import { wrapGrid } from animateCSSGrid

const grid = document.querySelector(".grid");
const { unwrapGrid, forceGridAnimation } = wrapGrid(grid);

// if you want the grid to transition after updating an inline style
// you need to call forceGridAnimation
grid.style.width = '500px'
forceGridAnimation()

// if you want to remove animations but not the grid itself
unwrapGrid()

Requirements

  1. The updates to the grid will have to come from addition or removal of a class or element. Currently, inline style updates will not trigger transitions. (Although you can manually trigger transitions in that case by calling forceGridAnimation())
  2. Important If a grid item has children, they should be surrounded by a single container element. This is so we can apply a counter scale and prevent children elements from getting warped during scale transitions of the parent.

Example:

<!-- grid class -->
<ul class="some-grid-class-that-changes">
  <li class="grid-item">
    <!-- each grid item must have a single direct child -->
    <div>
      <h3>Item title</h3>
      <div>Item body</div>
    </div>
  </li>
<div>

How it works

The script registers a MutationObserver that activates when the grid or one of its children adds or loses a class or element. That means there's no need to remove the animations before removing the grid, everything should be cleaned up automatically. 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.

It should work on container elements without CSS grid applied as well, but was developed and tested with CSS grid in mind.

Usage with Frameworks

The animate-css-grid library can easily be used with frameworks like React or Vue.

Check out the React example or the Vue example on Codepen!

関連リポジトリ
AllThingsSmitty/css-protips

⚡️ A collection of tips to help take your CSS skills pro 🦾

Creative Commons Zero v1.0 Universalcsscss3
30.2k2.2k
keen/dashboards

Responsive dashboard templates 📊✨

HTMLMIT Licensedashboardtemplates
keen.github.io/dashboards/
11k1.4k
phuocng/csslayout

A collection of popular layouts and patterns made with CSS. Now it has 100+ patterns and continues growing!

MDXMIT Licensecss-gridflexbox
phuoc.ng/collection/css-layout
8.1k516
sdras/cssgridgenerator

🧮 Generate basic CSS Grid code to make dynamic layouts!

VueMIT Licensecss-gridgrid
cssgrid-generator.netlify.com
5.3k573
RitikPatni/Front-End-Web-Development-Resources

This repository contains content which will be helpful in your journey as a front-end Web Developer

MIT Licensecssjavascript
5.1k711
AllThingsSmitty/must-watch-css

🔥 CSS talks you have to see ⚡️ covering CSS Grid, flexbox, custom variables, performance, frameworks, Sass, tools, and more! 🚀

Creative Commons Zero v1.0 Universalcssawesome
4.9k241
DioxusLabs/taffy

A high performance rust-powered UI layout library

Rustcrates.ioOtherflexboxui
docs.rs/taffy
3.3k200
usablica/front-end-frameworks

A collection of best front-end frameworks for faster and easier web development.

css-frameworkresponsive-grid
usablica.github.com/front-end-frameworks/compare.html
2.8k313
layoutit/layoutit-grid

Layoutit grid is a CSS Grid layout generator. Quickly draw down web pages layouts with our clean editor, and get HTML and CSS code to quickstart your next project.

VueMIT Licensecss-gridcss
grid.layoutit.com
1.7k185
LayoutitStudio/layoutit-grid

Layoutit grid is a CSS Grid layout generator. Quickly draw down web pages layouts with our clean editor, and get HTML and CSS code to quickstart your next project.

VueMIT Licensecss-gridcss
grid.layoutit.com
1.7k181
rohitkrai03/pills

A simple responsive CSS Grid for humans. View Demo -

CSSnpmMIT Licensecssgrid
rohitkrai.dev/pills
1.4k54
Spiderpig86/Cirrus

:cloud: The SCSS framework for the modern web.

SCSSMIT Licensecss-frameworkcss
cirrus-ui.com
1.4k77