Class-based Button Transition Effect failing to operate as intended

I want to trigger these 3 events simultaneously when a form is filled out, all initiated by the same button.

I have been able to make it work using 3 classes named:

  • "draw dj", which represents the first event
  • "draw1 dj", which signifies the 2nd event
  • "draw2 dj", indicating the final event

Here is the form I need to alter.

My Strategy

After the user completes editing the 1st field, Event 1 is triggered by adding the "draw dj" classes

Next, upon completion of editing the 2nd field, the classes change from "draw dj" to "draw1 dj" (this part is functioning correctly)

However, when the third event is activated, there is no transition and it directly switches to the final appearance.

Expected CSS Output

.draw2 {
    // transition: color 0.25s;
  color: lightgrey; 
  background-image: linear-gradient(rgb(255,123,0),rgb(255,123,0));
  background-position: 50%;
  background-repeat: no-repeat;
  background-size: 0% 100%;
  transition: background-size 0.5s 0.8s, color 1s 0.5s;
  &:hover{
    color:white;
    background-size:100% 100%;
  }
  &::before,
  &::after {
    // Set border to invisible, so we don't see a 4px border on a 0x0 element before the transition starts
    border: 2px solid transparent;
    width: 0;
    height: 0;
  }

  // This covers the top & right borders (expands right, then down)
  &::before {
    top: 0;
    left: 0;
  }

  // And this the bottom & left borders (expands left, then up)
  &::after {
    bottom: 0;
    right: 0;
  }



  // Hover styles
  &:hover::before,
  &:hover::after {
    width: 100%;
    height: 100%;
  }

  &:hover::before {
    border-left-color: rgb(255,123,0); // Make borders visible
    border-bottom-color: rgb(255,123,0);
    transition:
      width 0s ease-out, // Width expands first
      height 0s ease-out; // And then height
  }

  &:hover::after {
    border-right-color: rgb(255,123,0); // Make borders visible
    border-top-color: rgb(255,123,0);
    color:white;
    transition:
      border-color 0s ease-out, // Wait for ::before to finish before showing border
      height 0.25s ease-out, // And then exanding width
      width 0.25s ease-out 0.25s; // And finally height
  }
}

Current CSS Output

.draw2 {
    // transition: color 0.25s;
  color: lightgrey; 
  background-image: linear-gradient(rgb(255,123,0),rgb(255,123,0));
  background-position: 50%;
  background-repeat: no-repeat;
  background-size: 0% 100%;
  transition: background-size 0.5s 0.8s, color 1s 0.5s;
  &.dj{
    color:white;
    background-size:100% 100%;
  }
  &::before,
  &::after {
    // Set border to invisible, so we don't see a 4px border on a 0x0 element before the transition starts
    border: 2px solid transparent;
    width: 0;
    height: 0;
  }

  // This covers the top & right borders (expands right, then down)
  &::before {
    top: 0;
    left: 0;
  }

  // And this the bottom & left borders (expands left, then up)
  &::after {
    bottom: 0;
    right: 0;
  }

  // Hover styles
  &.dj::before,
  &.dj::after {
    width: 100%;
    height: 100%;
  }

  &.dj::before {
    border-left-color: rgb(255,123,0); // Make borders visible
    border-bottom-color: rgb(255,123,0);
    transition:
      width 0s ease-out, // Width expands first
      height 0s ease-out; // And then height
  }

  &.dj::after {
    border-right-color: rgb(255,123,0); // Make borders visible
    border-top-color: rgb(255,123,0);
    color:white;
    transition:
      border-color 0s ease-out, // Wait for ::before to finish before showing border
      height 0.25s ease-out, // And then exanding width
      width 0.25s ease-out 0.25s; // And finally height
  }
}

Answer №1

Once the post has been updated, make sure to include the background-size attribute within the draw1 class.

.draw1 {
    background-size: 0% 100%;
    &::before,
    ...

In order for CSS animations to work properly, a starting point is essential. Without providing a starting point, the class was toggling straight to the final value of the background size property.

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

Paragraph opacity adjustments can alter both the text and background opacities

Is there a way to change the opacity of only the background of a paragraph without affecting the text? When I try to adjust the opacity, it changes both the text and the background. How can I resolve this issue? HTML <div id="opener"> <p id="in ...

Identify the moment the user begins or ends typing using jQuery

Once upon a time, I encountered an issue that required me to detect when a user was typing and when they stopped typing so I could update the status accordingly. I have created a simple solution that may work for you as well. var typingTimer; var doneTyp ...

Utilize a fluid AJAX endpoint for the Vue Select2 encapsulated component

I have customized the Wrapper Component Example based on VueJS documentation by adding the AJAX data source feature. You can view my modified code here. My goal is to dynamically set the ajax url property of my select2 component, like this: <select2 :o ...

Need help positioning this HTML iframe on my webpage?

Can anyone help me figure out how to position this HTML i-frame in a specific place on my webpage? <div style="overflow: hidden; width: 333px; height: 156px; position src="h: relative;" id="i_div"><iframe name="i_frame"http://url.com/click.php?a ...

Passing JSON data from an ASP.NET controller to a view

My issue arises when a web page is loaded and triggers a controller action to retrieve data based on user selection. I am trying to return this data as a JSON object, but it appears as a single string within the HTML page. The basic structure of the contro ...

Make sure to retrieve the data before displaying the child components in React

Attempting to generate a list of selector options from external JSON data. Almost there, but part of the code is executing before the data loads, causing no children to be appended. There must be a way to solve this issue, just unsure how to do it in this ...

Using Django Crispy forms to dynamically hide fields based on the value of another field

What is the best way to dynamically hide or show a form field in Django crispy forms depending on the selected value of another field in the form? For example: Field A contains a dropdown menu with options '1' and '2'. Field B should ...

The arrangement of pictures on a card

I decided to tweak the original concept by placing the images inside a Bootstrap card. However, the end result is that the images appear to be floating. https://i.stack.imgur.com/Uf721.png Any suggestions on how to make them fit nicely within the card? ...

The file index.html seems to be missing - encountered an error while pushing to Heroku

After attempting to deploy my react-node app to Heroku using Heroku CLI, I encountered an error during the build process stating that it could not find the required file index.html. I have thoroughly checked all the files and confirmed that everything is ...

Text that is arranged vertically and adjusts its size and layout

I'm currently facing a challenge with vertical text display Check out my plunker What I'm attempting to accomplish is vertical text where: If a short text is placed inside the vertical text div, it should be aligned in the middle of the div I ...

I am encountering an issue where my .glb file is not appearing in the dist/assets directory while working with react.js and three.js

I recently developed an app using react.js and Vitejs, where I integrated a 3D model using Theejs (.glb file). Surprisingly, when I run npm run dev, the 3D model works flawlessly without any issues. However, upon running npm run build, I noticed that the 3 ...

When accessing WordPress through a URL, I am able to view regular PHP files but encounter difficulty accessing any uploaded files

Currently working on a Wordpress project and facing issues with creating a product via the WooCommerce REST API. I managed to make it work in my local environment, but upon uploading the files to the server, I am unable to reach a specific file via URL. Fo ...

Error Alert: Invalid type specified in React.createElement - Electron-React-Boilerplate

As a designer looking to expand my skills into coding for personal projects, I decided to start with the navigation UI in the [electron-react-boilerplate][1] that I cloned. However, I encountered the following error message: Error Warning: React.createEle ...

You're lost in cyberspace: Page not found - try navigating within the

Greetings! I am currently working on a straightforward app to experiment with page navigation. On my webpage, I have two links - one labeled section1 and the other section2. These links are positioned on the left side of the screen with a width of 100px. E ...

Unable to set options, such as the footer template, in Angular UI Typeahead

I am looking for a way to enhance the results page with a custom footer that includes pagination. I have noticed that there is an option to specify a footer template in the settings, but I am struggling to find examples of how to configure these options th ...

Automatically adjusting the image to fit the screen size

The image on the screen is not resizing properly. Please refer to the image with the alternate text google-play-badge. Even though the width and height of the image are set to auto, it is still not adjusting automatically. https://i.sstatic.net/Tu97S.jpg ...

Tips for troubleshooting objects within an Angular template in an HTML file

When I'm creating a template, I embed some Angular code within my HTML elements: <button id="btnMainMenu" class="button button-icon fa fa-chevron-left header-icon" ng-if="(!CoursesVm.showcheckboxes || (CoursesVm.tabSelected == 'curren ...

Sending a Post request from React js to an Express API built with Node.js

I am currently attempting to send data from a React front-end to an express API in Node. Here is the code snippet from the React front-end used to post data: generateOTPForLogin(phone_number){ console.log('transferring data'); fetch( ...

Invoke a "local" function inside module.exports in Node.js

What is the correct way to call a function from within another function in a module.exports declaration? In my MVC structured Node.js project, I have a controller named TestController.js. When trying to access a method within the controller using the this ...

Create interactive charts with Highcharts by incorporating AJAX requests

Below is the code snippet for an AJAX request to retrieve data and then call a function to pass the data to a graph. function getGraphs(){ $.ajax({ type : "POST", async: true, url : "<?php echo base_url(); ?>" + "Graphs/get_graphs", ...