Is there a framework available to animate Pseudo CSS elements?

Recently, I was working on developing a bar chart that utilized pseudo CSS elements (::before, ::after).

While I successfully created bars that look visually appealing, I encountered a challenge when attempting to animate the height changes. Whenever I used the animate function, the pseudo elements would vanish and only reappear once the animation was complete. Does anyone have any suggestions or ideas on how I can achieve this smoothly? Perhaps there is another animation framework available that will render the pseudo elements seamlessly?

Feel free to check out the CodePen link: http://codepen.io/anon/pen/OyGamW

HTML:

<ul><li><div class="fill bar1">100%</div></li></ul>

CSS:

*{
  padding:0;
  margin: 0;
}
body {
    height: 100%;
    background-repeat: no-repeat;
    background-attachment: fixed;
  background:#cdcdcf;
  overflow: hidden;
}

ul {
  list-style-type:none;
  overflow:hidden;
  padding-left:10px;
  padding-top:40px;
}
li{
float:left;
height:800px;
margin-top: 30px;
}

.fill {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 90px;
  line-height: 90px;
  position: relative;
  height: 300px;
  top: 161px;
  padding: 0px 0px 0px 8px;
  left: 70px;
  border: none;
  font: normal normal bold 26px/normal Tahoma, Geneva, sans-serif;
  color: rgba(255,255,255,1);
  text-align: left;
  -o-text-overflow: clip;
  text-overflow: clip;
  background: -webkit-linear-gradient(0deg, rgba(255,43,43,1) 0, rgba(209,31,31,1) 100%);
  background: -moz-linear-gradient(90deg, rgba(255,43,43,1) 0, rgba(209,31,31,1) 100%);
  background: linear-gradient(90deg, rgba(255,43,43,1) 0, rgba(209,31,31,1) 100%);
  background-position: 50% 50%;
  -webkit-background-origin: padding-box;
  background-origin: padding-box;
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-background-size: auto auto;
  background-size: auto auto;
  -webkit-transform:  scaleX(1) scaleY(1) scaleZ(1)  skewY(-3deg);
  transform:  scaleX(1) scaleY(1) scaleZ(1)  skewY(-3deg);
  -webkit-transform-origin: 0 0 0;
  transform-origin: 0 0 0;
  -webkit-box-shadow: 0 11px 18px -5px #841313 inset;
  box-shadow: 0 11px 18px -5px #841313 inset;
}

.fill::before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 50%;
  height: 100%;
  position: absolute;
  content: "";
  top: 0;
  left: 0;
  border: none;
  font: normal normal normal 16px/normal "Times New Roman", Times, serif;
  color: rgba(0, 0, 0, 0.901961);
  -o-text-overflow: clip;
  text-overflow: clip;
  background: -webkit-linear-gradient(-180deg, #c62121 0, rgba(132,19,19,1) 100%);
  background: -moz-linear-gradient(270deg, #c62121 0, rgba(132,19,19,1) 100%);
  background: linear-gradient(270deg, #c62121 0, rgba(132,19,19,1) 100%);
  background-position: 50% 50%;
  -webkit-background-origin: padding-box;
  background-origin: padding-box;
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-background-size: auto auto;
  background-size: auto auto;
  text-shadow: none;
  -webkit-transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-44px) skewY(20deg);
  transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-44px) skewY(20deg);
  -webkit-transform-origin: 100% 100% 0;
  transform-origin: 100% 100% 0;
  -webkit-box-shadow: 0 11px 18px -5px #841313 inset;
  box-shadow: 0 11px 18px -5px #841313 inset;
}

.fill::after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 100%;
  height: 16.1px;
  position: absolute;
  content: "";
  top: -1px;
  left: 0;
  border: none;
  font: normal normal normal 16px/normal "Times New Roman", Times, serif;
  color: rgba(0, 0, 0, 0.901961);
  -o-text-overflow: clip;
  text-overflow: clip;
  background: rgba(132,19,19,1);
  text-shadow: none;
  -webkit-transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-50%) translateY(-91%) skewX(70.5deg);
  transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-50%) translateY(-91%) skewX(70.5deg);
  -webkit-transform-origin: 0 0 0;
  transform-origin: 0 0 0;
}

JS:

$(document).ready(function() {
    setInterval(function() {
        doAnimation();
    },4000);
    doAnimation();
});
function doAnimation() {
  $('.fill').animate({ "height": "150px", "top": "311px"}, 1000);
  $('.fill').delay(1000).animate({ "height": "300px", "top": "161px"}, 1000);
}

If you have any insights or suggestions, please feel free to share. Thank you!

Answer №1

It's not entirely clear how GSAP's TweenMax differs from jQuery's .animate() method in this specific scenario, but substituting your animation with TweenMax resolves the issue.

JavaScript:

TweenMax.to('.fill', 1, {
  height: 150,
  top: 311,
  repeat: -1,
  yoyo: true,
  ease: Expo.easeInOut
});

On a side note, I highly recommend utilizing GSAP for all your JS animation requirements. Explore the documentation for available methods and properties.

Here is the link to your modified pen.

I hope this information proves helpful.

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

Is it possible to submit two forms simultaneously using jQuery or AJAX?

My plan is to save 2 forms, with the first form providing the Foreign key for the second form. This is my attempt at saving this using JavaScript: $("#btnSave").click(function (e) { e.preventDefault(); $('#workForm').submit(); ...

What purpose does the next() function serve in Express.js?

Using this script to kickstart my next js app. I can't share the entire script, but I do need some assistance with the following: What is the purpose of compression? What is the importance of using helmet? What does next({dev}) do? const express = re ...

Tips for dynamically updating the id value while iterating through a class

Here's the HTML snippet I am working with: <div class="info"> <div class="form-group"> <label class="control-label col-sm-2">Title</label> <div class="col-xs-10 col-sm-8"> <inpu ...

Tips for removing a previous file from an 'input type' in HTML5 FileReader

Here is a file input with an associated function: <img id="uploadPreview"> <div id="changeImage">Change</div> <div id="customImage"> <input type="file" id="myfile" multiple style="display:none" onchange="PreviewImage();" / ...

Customizing Ngx-bootstrap Carousel Indicator, Previous, and Next Button Styles

<carousel > <a href=""> <slide *ngFor="let slide of slides"> <img src="{{slide.imgUrl}}" alt="" style="display: block; width: 100%;"> </slide> 1. Is there a way to substitute the indicators with images ...

Is it advisable to incorporate both Jquery and AngularJs into progressive web applications?

Currently, I am in the process of constructing a progressive test application. So far, all the tutorials I have come across utilize native JavaScript. My inquiry is whether it is possible to leverage Jquery for streamlined code writing and implement an MVC ...

Check that EACH radio button has been either selected or left unselected when the button is clicked

I'm still learning Javascript and currently working on a function triggered by a button click. My goal is to display an alert if NONE of the radio buttons have been selected, regardless of whether they are "Yes" or "No." If ALL radio buttons have been ...

Using ng-value does not trigger any updates to the Ng-model

After setting the input value Array property sum, it displays the value in the input field. However, when submitting the form, the Quantity property is not being received in the Order object. I noticed that if I change the value manually, then the Quanti ...

The npm http package exclusively includes a package.json without any accompanying JavaScript files

After installing an npm package that listed 'http' as a dependency, I also installed 'http'. However, all npm downloaded for 'http' was a package.json file that referenced a non-existent index.js file. Could it be that the ind ...

Developing a specialized command-line application for currency conversion is my current project

Currently, I am working on developing a command-line application for currency exchange. I have created an interface to define the structure of an object array that will store the keys and values of currency names along with their current values in the inte ...

Incorporate personalized design elements within the popup component of Material-UI's DataGrid Toolbar

I am in the process of customizing a Data Grid Toolbar component by making adjustments to the existing Grid Toolbar components sourced from Material-UI. For reference, you can view the official example of the Grid Toolbar components here. Upon clicking o ...

Triggering a pop-up window to appear without user interaction on the specified date within the function

I am looking to automatically trigger a pop-up window when my website loads after a specific date that I define within a function. How can I set up the date function for this task? I want the pop-up window to appear automatically on 27/07/2011, and every ...

Validation for dates in Angular.Js input is important to ensure that only

Take a look at this form: <form name="user_submission" novalidate="novalidate" method="post"> <input type="date" name="date_of_birth" ng-focus="save_data()" ng-model-options="{timezone: 'UTC'}" ng-pattern="/^(19\d{2}|[2-9]& ...

What's the reason for the icon not updating in the responsive mode?

I am venturing into the world of responsive web design for the first time. My aim is to create a website menu that drops down when the menu icon is clicked, using the onclick command in JavaScript. However, upon inspecting my browser, I noticed an uncaught ...

Ensure that the content is perfectly aligned with the rest of the page for a visually pleasing

Seeking guidance on how to symmetrically center an image gallery with a list background, regardless of the browser's size. Any tips for aligning content perfectly? I attempted using a wrapper around the gallery and list with a fixed width, but it onl ...

Steps to substituting characters within a date string

Create a function called normalize that changes '-' to '/' in a given date string. For example, normalize('20-05-2017') should output '20/05/2017'. This is my attempt: let d = new Date('27-11-2021'); fun ...

Text box is not automatically filling up when selecting from dropdown menu

I am currently facing an issue with a dropdown box that offers three different selections. I want the Group ID associated with the selected group to automatically populate in the textbox below. How can I achieve this functionality? Whenever I make a selec ...

Repairing the 'Uncaught TypeError: Cannot read property 'split' of undefined' bug in a Prestashop Module

Help! I'm encountering an issue with a Prestashop module, and the developer is unresponsive. Can anyone shed light on why I am seeing this error in the console? Thank you so much in advance! admin.js:57 Uncaught TypeError: Cannot read property ' ...

What are the steps for implementing CSS in Markdown?

How can I incorporate a CSS class into a Markdown file? For example, using <i class="icon-renren"></i> (from the fontawesome library) should display an icon when its CSS file is imported in HTML. Is there a way to achieve this in Markdown? ...

Implementing an onclick function to execute a search operation

Utilizing PHP, I am dynamically populating a dropdown submenu with rows from a database. If the user wishes to edit a specific record listed in the menu, I want to enable them to do so without requiring any additional clicks. My goal is to accomplish this ...