CSS-based animations triggered by JS, defined in your stylesheet

Overview

Anim-x

CSS-based animations triggered by JS, defined in your stylesheet.

$ npm i https://github.com/LTBL-Studio/anim-x.git

Quick start

An animation is identified with a name and is applied to an element by successively adding and removing classes.

For this example we will animate this div element with class square for a simple apparition with scale.

<div class="square"></div>

In your code, select the element we want to animate and call animateElement() with a name for your animation.

animateElement(document.querySelector(".square"), "enter")

Here, we are triggering an animation called enter on our element .square.

Anim-x uses promises to have control over your animations, animateElement() returns a promise that resolve when the animation ends.

For now, we don't defined any effect and timing for this animation. No animation is shown.

Animation content is defined in CSS stylesheet. It's helps to separate concerns, focus on your JS code and get back to animation later.

In this example we use CSS transitions but you can use @keyframes and animation properties instead.

for that, Anim-x will use 3 types of classes, in our case :

  • animate-enter-active Added during all the animation and defines its duration, delay, timing function, etc.
  • animate-enter Added only when the animation starts and defines the initial style of the animated element
  • animation-enter-end Added just one frame after animate-enter was removed and defines the final style of the animated element.

Css transition will interpolate the style between animate-enter and animate-enter-end.

.square.animate-enter-active {
    transition: ease 0.5s all;
}

.square.animate-enter {
    transform: scale(0.3);
    opacity: 0;
}

.square.animate-enter-end {
    transform: scale(1);
    opacity: 1;
}

In our example, our animation is called "enter", but name of the animation defines the name of animation classes.

  • animate-[animationName]-active
  • animate-[animationName]
  • animate-[animationName]-end

Stack animation

Anim-x helps you to animate sequencial elements like list of items.

Function animateStack will call animateElement on each item in order.

animateElement(document.querySelectorAll(".my-list > *"), "enter")

During the process a class animate-[animationName]-stack is added to all animated elements during all stack animation. A CSS var --animate-stack-index is also defined to helps you calculate delays for each element.

.my-list > .animate-enter-active {
    transition: ease 0.5s all;
    transition-delay: calc(var(--animate-stack-index) * 100ms);
}

.my-list > .animate-enter {
    transform: scale(0.3);
    opacity: 0;
}

.my-list > .animate-enter-end {
    transform: scale(1);
    opacity: 1;
}

Options

This is a list of options you can pass to animateElement and animateStack as last parameter

  • rejectOnCancel boolean (default: false) : if the animation is cancelled, reject the promise instead of resolving it
  • subtree boolean (default: true) : if true, Anim-x will resolve until all children animations are completed
You might also like...

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

OCPP-RPC A client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols (e.g. OCPP1.6J and OCPP2.0.1J). Re

Dec 30, 2022

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

Scrollbox A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point. Demo Page Table of contents Browser compat

Jul 22, 2022

Invadium runs exploit playbooks against vulnerable target applications in an intuitive, reproducible, and well-defined manner.

Invadium Invadium runs exploits against one or more target applications in an intuitive, reproducable, and well-defined manner. It focuses on bridging

Nov 6, 2022

jQuery plugin to show a tabs bar for navigation. The tabs can be defined once, and shared across multiple HTML pages.

jQuery plugin to show a tabs bar for navigation. The tabs can be defined once, and shared across multiple HTML pages.

jquery.simpletabs v1.2.3 The jquery.simpletabs plugin shows a tabs bar for navigation. The tabs can be defined once, and shared across multiple HTML p

Feb 23, 2022

Tampermonkey script which adds the ability to add a user-defined label/tag/flair on a user, shown throughout Hacker News.

Hacker News User Tags Hacker News User Tags is a Tampermonkey userscript which allows the user to associate a custom coloured label/tag on usernames t

Oct 7, 2022

Lightweight JavaScript library that allows you add motion blur to your CSS animations

MotionBlurJS For more information and examples please visit: https://www.motionblurjs.com What is MotionBlurJS MotionBlurJS is a lightweight JavaScrip

Oct 6, 2022

A timed continuous carousel that uses vanilla JavaScript & CSS animations.

Continuous Carousel ∞ Timed continuous carousel that uses vanilla JavaScript & CSS animations. It supports both horizontal and vertical scrolling. Mar

Jan 3, 2023

A jQuery plugin that works in harmony with animate.css in order to enable animations only when content comes into view.

jQuery AniView A jQuery plugin that works in harmony with animate.css in order to enable animations only when content comes into view. Now supports v4

Sep 10, 2022

A tiny JavaScript library to enable CSS animations when user scrolls.

A tiny JavaScript library to enable CSS animations when user scrolls.

A tiny JavaScript library to enable CSS animations when user scrolls. This library allows you to toggle one or more classes on an element when it appe

Nov 24, 2022
Owner
LTBL
LTBL
Simple click-triggered navigation submenus. Accessible and progressively enhanced.

Clicky Menus! A project by Mark Root-Wiley, MRW Web Design Clicky Menus lets you create a progressively-enhanced, accessible one-level dropdown menu t

Mark Root-Wiley 76 Dec 6, 2022
Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components.

Chakra UI Animations Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components. Installation yarn add @

Code Chemistry Inc. 9 Nov 19, 2022
A CSS stylesheet to quickly highlight a11y concerns.

Checka11y.css A CSS stylesheet to quickly highlight a11y concerns. Lightweight • Modern • Accessibile • Customisable • Simple The first line of defenc

Jack Domleo 428 Dec 25, 2022
Calculates maximum composite SLA for a list of sequentially provided cloud services or your custom-defined services.

SlaMax Calculates maximum composite SLA for a list of sequentially provided cloud services or your custom-defined services. Here are a few use-cases y

Mikael Vesavuori 4 Sep 19, 2022
Improve the security of your API by detecting common vulnerabilities as defined by OWASP and enforced with Spectral.

Spectral OWASP API Security Scan an OpenAPI document to detect security issues. As OpenAPI is only describing the surface level of the API it cannot s

Stoplight 23 Dec 8, 2022
Stylesheet and scripts for implementing dark mode with Bootstrap 4

Bootstrap Darkmode This project provides a stylesheet and two scripts that allow you to implement a dark theme on your website. It is initially loaded

Adrian Kunz 41 Nov 27, 2022
Bootstrap 4 stylesheet that implements vertically-oriented navigation tabs.

Responsive Vertical Navigation Tabs for Boostrap 4 New! ?? If you use Bootstrap 5, a new package is available for that: bootstrap-5-vertical-tabs A st

Tromgy 9 Aug 4, 2022
Pure JavaScript HTML5 Canvas Range Slider. No stylesheet needed. Simple, elegant and powerful. A quirky alternative to other sliders.

CanvasSlider CanvasSlider is a lightweight JavaScript range slider. Most of the range slider controls use Javascript and a stylesheet. This slider use

null 7 Aug 15, 2022
Renders and SVG schema of SARS-CoV-2 clade as defined by Neststrain

ncov-clade-schema https://ncov-clades-schema.vercel.app/ Visualizes current tree of SARS-CoV-2 clades. Allows to generate an SVG image of this tree. C

Nextstrain 5 Nov 3, 2022
Sample AWS microservices app with service discovery defined using the CDK. Uses Docker + Fargate & ELB.

AWS Microservices Demo with CDK and Fargate About Simple AWS microservice-based app. Consists of two Spring Boot based services: Name Service GET /nam

Nick Klaene 7 Nov 23, 2022