Giter Club home page Giter Club logo

annexcss's Introduction

@nnexCSS

AnnexCSS is a lightweight single-file pure CSS animation library made for use in a TBA React framework.

npm i annexcss
import 'annexcss'

You can easily add animations to your JSX or markup just like any regular CSS class

<div className="@fadeIn"> I love potato </div>

You can extend functionality by adding utility classes

<div className="@fadeIn flex">
  <div className="@fadeIn @delay-1s flex-none ...">
    01 Potato
  </div>
  <div className="@fadeIn @delay-2s flex-1 w-64 ...">
    02 Potato
  </div>
  <div className="@fadeIn @delay-3s flex-1 w-32 ...">
    03 Potato
  </div>
</div>

Classes
@bounce @flash @pulse @rollIn
@shake @headShake @swing @rollOut
@wobble @tada @bounceIn @bounceInDown
@bounceInLeft @bounceInRight @bounceInUp @bounceOut
@bounceOutDown @bounceOutLeft @bounceOutRight @bounceOutUp
@fadeIn @fadeInDown @fadeInDownBig @fadeInLeft
@fadeInLeftBig @fadeInRight @fadeInRightBig @fadeInUp
@fadeInUpBig @fadeOut @fadeOutDown @fadeOutDownBig
@fadeOutLeft @fadeOutLeftBig @fadeOutRight @fadeOutRightBig
@fadeOutUp @fadeOutUpBig @flipInX @flipInY
@flipOutX @flipOutY @slideInUp @slideOutUp
@rotateIn @rotateInDownLeft @rotateInDownRight @rotateInUpLeft
@rotateInUpRight @rotateOut @rotateOutDownLeft @rotateOutDownRight
@rotateOutUpLeft @rotateOutUpRight @zoomOutUp @zoomOut
@zoomIn @zoomInDown @zoomInUp @zoomOutRight
@zoomInLeft @zoomInRigh @slideOutRight @slideOutLeft
@zoomOutDown @zoomOutLeft @slideInRight @slideOutDown
@slideInDown @slideInLeft

Utilities
@infinite @reapeat-1 @repeat-2 @repeat-3
@delay-1s @delay-2s @delay-3s @delay-4s
@delay-5s @faster @fast @slow
@slower

So how does it work? AnnexCSS first creates variables in :root to reuse as basic properties.

:root {

    --animate-repeat: 1;
    --animate-duration: 1s;
    --animate-delay: 1s;

}

It then wraps all elements (*) with required core properties for individual classes to function properly. All classes use this wrapper when applied. This is a core feature unique to AnnexCSS.

* {
  
    animation-duration: 1s;
    animation-duration: var(--animate-duration);
    animation-fill-mode: both;
    -webkit-animation-fill-mode: both;
    -webkit-animation-duration: var(--animate-duration);
    -webkit-animation-duration: 1s;

}

In regards to browser compatibility AnnexCSS focuses entirely on webkit. Postcss with autoprefixer can assist you if you need to expand cross-compatibility. Classes typically look like this:

@-webkit-keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}
.\@fadeIn {
  -webkit-animation-name: fadeIn;
  animation-name: fadeIn;
}

You can call the @keyframes directly in any class. Just make sure to declare the duration too.

.bounceHover:hover {

  animation: bounce; 
  animation-duration: 2s; 

}

And you can change variables to customize your animations. Make sure you use a backslash to escape the @ when cascading over the animation classes. All AnnexCSS classes use @ as a prefix.

.\@fadeIn {

  --animate-duration: 10s;
  
}

About

This library was originally compiled using a custom animate.css build so you may take notice of the simliar class names. Many of the "uncommon" classes were removed to simplify the class set and reduce build size as much as possible.

Using the animate.css package to compile annex.css was just a method to prefix and quickly iterate on commonly used CSS animation techniques for an accompanying JS framework.

Originally I wanted to use animate.css itself but it's getting a bit older now and had unneeded overhead for my use case.

There is one major core difference outside of the postcss scripts and size. AnnexCSS wraps all elements with required properties instead of individually applying them. This allows for cleaner markup. Instead of animate__animated animate__fadeIn just for one animation, you just need @fadeIn etc.

AnnexCSS relies on webpack (or webpack-based frameworks) to clean unused properties/styles, minify, etc.

https://webpack.js.org/guides/tree-shaking/

If all else fails modern browsers typically clean up unused CSS on render too. Using all 70 animations on a single page without tree shaking only causes a single point drop in lighthouse performance scores. Universal selector properties always get cleaned up as well.

There are docs planned that will be released within the previously mentioned JS framework.

annexcss's People

Contributors

lgrammer avatar lgsandbox avatar

Stargazers

Corcules avatar  avatar  avatar

Watchers

 avatar  avatar

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.