Creating animated keyframes with JavaScript and Jquery within a React environment

Currently, I am developing an animated feature within a react project. Specifically, the animation involves numerous dynamic bubbles.

For each bubble, I require a rapid growth and shrink effect. Here is a snippet of how my css animation is structured:

@keyframes bubbleTwitch {
  0% {
    width: 200px;
    height: 200px;
  }
  50% {
    width: 150px;
    height: 150px;
  }
  100% {
    width: 200px;
    height: 200px;
  }
}

This animation would run infinitely with very brief intervals:

.bubble {
  animation-name:bubbleTwitch;
  animation-duration:150;
  animation-iteration-count:infinite;
}

The challenge arises as each bubble varies in size. While transform:scale() could be a solution, it conflicts with the existing use of transform for specific translate functions unique to each bubble.

I am searching for a method to dynamically generate keyframes for individual bubbles using javascript. This would enable me to adjust the animation based on each bubble's dimensions. Alternatively, if there exists a way to retain the original translate positions while implementing a css animation utilizing transform:scale, that would also solve the issue at hand.

If anyone has any suggestions or workarounds, I would greatly appreciate your input. Thank you!

Answer №1

To make each bubble's size fixed to an outer div, you can adjust the bubble's size as a percentage in your JSX code like this:

<div className={s.bubbleContainer}>
    <div className={bubble} />
</div>

Then style the CSS accordingly:

.bubbleContainer {
    width: 200px;
    height: 200px;
}

@keyframes bubbleTwitch {
  0% {
    width: 100%;
    height: 100%;
  }
  50% {
    width: 75%;
    height: 75%;
  }
  100% {
    width: 100%;
    height: 100%;
  }
}

This method allows you to customize the size of each bubbleContainer individually using classes, similar to how you planned to do it with transform:scale.

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

What causes the change in the "to" prop upon clicking?

On my website, I have a Link that directs users to their profile page with the "to" prop set to "user/username". However, when clicked, it navigates to the profile page but dev tools show that the value changes to "user/user/username", adding an extra "use ...

When using body-parser, req.body may sometimes unexpectedly return undefined

My current project involves creating an API that handles POST requests for user creation. Unfortunately, I'm encountering undefined errors for all the req.body calls. Here's a simplified overview of how my application is structured: User control ...

DC.js table is showing excess rows that were not intended to be displayed

I am encountering an issue with a table in DC.js where every odd row is appearing as an extra row. The table should only have two columns - the first column displaying the state and the second column showing an amount named fund. However, upon inspection o ...

Utilize React hooks to enhance focus on user input

Struggling to get useRef working for my project and can't seem to pinpoint the issue. I've created a controlled Input component within a form that wraps multiple Inputs. When the form is submitted, the input is added as a new line in a list with ...

Is Material UI available for React without any cost?

Just wondering, is Material UI (for a react application) free to use? We're considering implementing it in our app, but want to make sure there are no licensing complications. Appreciate any guidance you can provide. Thanks! ...

Recording the descending data points (excluding the dragged positions) from the bootstrap slider

I am struggling with the implementation of the BootStrap Slider from this source: I have encountered an unusual requirement. I need to capture the values of the slider only when the user stops dragging it, not during the process of sliding. In other words ...

What separates $(document).ready() from embedding a script at the end of the body tag?

Can you explain the distinction between running a JavaScript function during jQuery's $(document).ready() and embedding it in the HTML within script tags at the bottom of the body? Appreciate your insights, DLiKS ...

Steps to complete a form submission and retrieve the URL post logging in using CasperJS

Having the url, username, and password of a site can be challenging when the site doesn't utilize a form element. In this case, the structure may look different. For instance, the username fields may have the class .user_name, while the password fiel ...

Tips for adding values to an object

Behold, a complex object in multiple dimensions: let b = {} b.push({hello:'xyz'}) This method is currently inactive ...

The body-parser module in express 4.0 is currently not accessible for the route handler

I am attempting to send a PUT request via Google Postman in the following format: PUT /updateUser/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="debcbcbc9eadadadf0bdb1b3">[email protected]</a> HTTP/1.1 Host: loca ...

Accessing the first child node in JsTree

Is it possible to display only the first child of a list using the JStree plugin to create a tree? For example, if I have a list with 5 children, some of which have nested children, I am looking for a way to display only the first child of each <li> ...

The utilization of the base64 function leads to an InvalidCharacterError

My goal is to implement the base-64 module method in my node.js + express project. Here is the code snippet: router.get('/list', function(req, res, next) { client.query('SELECT * FROM Document',function(err, row){ if(err) ...

"Experiencing the inconvenience of having to manually refresh Next JS 13 in order to

After updating to Next.js 13, I've noticed that I have to refresh the screen every time I make changes to my files. It's quite inconvenient having to hard refresh constantly whenever I update something. This is my current configuration for Next ...

Implement authentication verification on all child endpoints within an express router

I have an express router set up and I want only authorized users to access its routes. I am currently using passport middleware. Instead of adding a check for req.user in every endpoint, is there a more efficient way to handle this? router.get("/", asyn ...

Best Practices for Angular and Managing Database Access

By now, I have a good understanding that angular.js is a client-side framework, which means any database communication involves sending requests to a server-side script on the server using methods like get/post (with node, php, asp.net, or other technologi ...

Customize and format the text of options in a select element using the jQuery Chosen plugin

I have been exploring the jQuery plugin chosen for a select box with autocomplete functionality. You can check it out here: Does anyone know how to customize the appearance of the text in the options of the select box? Is there a specific method within t ...

Prevent random files from being included in RequireJS's r.js optimization process and instead load them asynchronously

Currently, I have successfully implemented RequireJS and a Grunt-based build process that optimizes my JS app into one file using r.js. This consolidation of all app files has proven to be efficient for production deployment. However, the issue arises wit ...

I am having trouble getting JavaScript to render properly in my single page application

In my home.js file, I have the following code snippet: define(['services/logger'], function (logger) { var vm = { activate: activate, title: 'Home View' }; return vm; //#region Internal Methods function activate() { ...

How can I incorporate getInitialProps() into a Higher-Order Component-wrapped functional element in NextJS?

This is a functional component wrapped with a HOC export default wrapperHoc( function myComponent ({ someProps }){ return( <div/> ) }) I'm wondering how to implement getInitialProps for myComponent Is it necessary to call myComp ...

Developing a continuous running test loop

Currently, I have a code that runs fine, but I am looking to modify it to run in a loop that counts the number of elements with the class="socal" and tests each link. module.exports = { 'Unitel Fitness - click' : function (browser) { bro ...