When deciding between utilizing a Javascript animation library and generating dynamically injected <style> tags in the header, consider the pros and cons of each

We are currently in the process of developing a sophisticated single-page application that allows users to create animations on various widgets. For example, a widget button can be animated from left to right with changes in opacity over a set duration. Additionally, one widget can trigger animations on another, creating layered transition effects.

Users have the ability to define and trigger these animations through JavaScript in a complex manner. The animations can be customized in different combinations, utilizing an object-oriented programming approach for animation data management. Users can also reverse, pause, and play the animations as needed.

In terms of animation technology, we are considering two options:

01 - Utilizing CSS Transitions by generating dynamic CSS classes and injecting them into the header of the page. This approach involves manipulating the DOM to handle class switching for animations.

02 - Using a JavaScript library such as Velocity.js or Greensock to animate the DOM elements directly using inline styles.

03 - Although we experimented with Web Animation API (and CSS Animation), we encountered some limitations that hindered its adoption.

We would greatly appreciate your feedback regarding the following approaches:

Approach 01:

  • Is it feasible to manage programmatically with JavaScript?
  • Can properties within style tags be dynamically edited without causing flickering or relying on complex regex?
  • Are there any issues associated with dynamically adding tags to the header, such as potential flickering?
  • Have you experienced performance drawbacks when running multiple parallel animations with CSS Transition?
  • Do you know of any projects that successfully utilize this approach?
  • How is the control of animation functions like reversing, stopping, and pausing handled?

Approach 02:

  • Do you believe this approach is generally more manageable with JavaScript?
  • Are there any drawbacks that would lead one to choose Approach 01 instead?
  • How is the control of animation functions managed in this approach?

We welcome any feedback you may have on this matter.

Here's a helpful article I came across: https://davidwalsh.name/css-js-animation

Answer №1

If you have dynamic animation that needs to be controlled during execution, it's best to use JavaScript instead of CSS. The choice of library for this task is up to your discretion.

Answer №2

One downside of utilizing a JavaScript library is the need to troubleshoot both hardware and JS animations, in addition to understanding the idiosyncrasies of those libraries. Over the past three years, I've discovered that CSS animations and transitions are easier to work with and debug, making them a preferable choice. Efficient debugging plays a crucial role in web animations.

Nevertheless, there are numerous user-friendly tools available (or libraries) that simplify handling more intricate CSS animations and transitions. If I were in your shoes, I would start by exploring the existing libraries to see if any suit your needs.

Below are two smaller libraries that leverage CSS animations:
https://github.com/FelixRilling/microAnimate
https://github.com/daniel-lundin/snabbt.js

Many of these options can assist you in saving user animations as described.

An example using microAnimate:

var myAdvancedAnimation = new Anim(
  document.getElementById("square"), {
    "0%": [
      ["width", "200px"],
      ["color", "transparent"]
    ],
    "20%": [
      ["width", "100px"],
      ["color", "#fff"],
      function() {
        console.log("callback 2");
      }
    ],
    "100%": [
      ["width", "60px"],
      ["color", "red"],
      function() {
        console.log("callback 3");
      }
    ]
  }, {
    duration: 2000,
    ticklength: 30,
    ease: true,
    retainEndState: true,
    loop: false
  }
);

As illustrated, saving a specific animation for users would be straightforward since it involves objects and arrays that can be stored in localStorage or a centralized database. Furthermore, this approach simplifies coordinating different types of animations.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Styling hover effects on links in Bootstrap 4 with underlines

In Bootstrap 4, the anchor tags have the text-decoration: underline; property added only on hover. Is there a pre-existing helper or utility class to remove this underline? I went ahead and created my own helper class in CSS to remove the underline, but ...

Can someone please advise me on how to output the value of a var_dump for an array using console.log?

After writing the code in this manner, it functions properly and returns a JSON object. public function getElementsAction() { $currency = App::$app->getProperty('currency'); if(!empty($_POST)) { $sql = 'SELECT name, p ...

Is it possible to have the cursor rotate or animate by 45 degrees when clicked

Do you know how to create a unique custom cursor using CSS? Say, for example, we have this code: cursor: url(images/cursor.png) 15 15, auto; Now, what if we wanted to take it up a notch and make the cursor rotate -45 degrees when clicked, and then revert ...

What is the reason for the excessive width of the final column in this table?

I am currently working with a dataset that I am displaying using the handsontable library in the form of a table. One issue I am facing is that the last column of my table appears too wide even though I did not specify any width for it. Below you can see t ...

The installed NPM package does not contain the necessary TypeScript compiled JS files and declaration files

I have recently released a TypeScript library on NPM. The GitHub repository's dist (Link to Repository Folder) directory includes all compiled JavaScript and d.ts files. However, after running npm i <my_package>, the resulting module contains on ...

Examining the process through which an element attains focus

Scenario I am working on a Backbone application that has an event listener set up for focus events on a textarea. Since Backbone relies on jQuery events, my main concern revolves around jQuery focus events. Inquiry Is there a method to determine how an e ...

Activating/Deactivating Checkbox using Jquery

I'm having trouble getting this code to function properly when there are multiple instances of datepicker on the page. When selecting the option "I currently work here," it is affecting all groups instead of just the current one, which is not the des ...

When access to Ajax .responseText in an alert it can be displayed, however it cannot be stored in a variable or

var response_var=""; // Added for debugging purposes ajax.onreadystatechange = function() { if (ajax.readyState == 4 & ajax.status == 200) { response_var = ajax.responseText; alert(ajax.responseText); // This alerts properly (some text ...

Start by creating a set of vertices and triangles to be utilized by the vertex shader

After experimenting with vertexshaderart.com, I'm eager to apply what I've learned on a different website. While I have experience using shaders in the past, some effects achieved on the site require access to vertices, lines, and triangles. Pass ...

The user interface design transforms as a PDF file is being generated through html2pdf

I am experiencing an unusual problem while using html2pdf to convert an HTML page to a PDF file and download it. The conversion process is successful and the PDF file is downloaded without any issues. However, when I click on a button to generate the file, ...

Tips on revealing concealed information when creating a printable format of an HTML document

I need to find a way to transform an HTML table into a PDF using JavaScript or jQuery. The challenge I'm facing is that the table contains hidden rows in the HTML, and I want these hidden rows to also appear in the generated PDF. Currently, when I co ...

identify when the React component has reached the bottom of the element by reading the

Is there a way to access the scroll handler's event without being able to access offsetTop, scrollTop, etc? class App extends React.Component { handleScroll = e => { console.log(e.target.scrollTop); }; componentDidMo ...

Using JavaScript to place image data on the canvas in an overlay fashion

I recently wrote the code below to generate a rectangle on a canvas: <!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canv ...

How to apply custom styling to a specific element within an Angular Material 2 component using CSS based on its Id or

My EntryComponent features a material button menu where I attempted to customize the default style using ::ng-deep. However, the changes affected all button components in the parent Component as well. <style> ::ng-deep .mat-button{ max-width: 50 ...

What is the secret to keeping links opaque even after they have been hovered over and their target is visible?

There are four links on my page that toggle the visibility of different divs. You can see them in action here. The code for the links is shown below: <li class="togglelink fadein button" data-block="albums" id="togglealbums">Albums</li> <l ...

Unforeseeable actions of Bootstrap-datepicker

I'm currently utilizing bootstrap-datepicker from the uxsolutions collection on GitHub and I've encountered some unusual behavior. At times, it loads properly while other times it does not: https://i.stack.imgur.com/mAVAc.png When it loads corr ...

Tips for adjusting the placement of an object within a table

Below is an example of a basic table: table, th, td { border: 1px black solid; border-collapse: collapse; } <table> <tr> <th>number</th> <th>name</th> <th>id</th> </tr> <tr&g ...

Using TestCafe selectors to target a classname that has multiple matching nodes

I need help finding a TestCafe selector that can target an element with the same class name that appears multiple times in my HTML code. Here's what I have tried so far: https://i.sstatic.net/ZS691.png Despite trying various selectors, I have been u ...

Post request in ExpressJS fails to redirect user after submission

My current project involves developing a web application using NodeJS and ExpressJS. One issue I am encountering is with the login functionality on my website. After filling out the login form, the user's credentials are sent via a post request to the ...

Express: when req.body is devoid of any data

My server code using Express: const express = require('express'); const exphbs = require('express-handlebars'); const path = require('path'); const bodyparser = require('body-parser'); const app = express(); cons ...