Animate the CSS with a delay using styled-components

Is it possible to delay the opacity to zero when a certain condition is met? The loader bar is controlled using JavaScript, but can this delay be achieved using CSS alone?

const Wrap = styled.div`
  background: #ddd;
  width: 100px;
  height: 10px;
  border-radius: 3px;
  opacity: ${props => (props.currentStep === props.steps ? 0 : 1)};
`;

Check out the demo (click on the add button)

https://codesandbox.io/s/7k20zw5z10

My goal is to have the progress bar load to 100%, then delay for 1 second before fading away completely.

Answer №1

Absolutely, you can achieve this effect using CSS transitions:

div {
  background: #f1f1f1;
  width: 120px;
  height: 15px;
  border-radius: 5px;
  opacity: 1;
  transition: opacity 0.5s 1s;
}

div:hover {
  opacity: 0;
}
<div></div>

The transition will last for 0.5s with a 1s delay before it starts.

Answer №2

One way to achieve this effect is by using the transition-delay property in CSS:

const Wrapper = styled.div`
  background: #ddd;
  width: 100px;
  height: 10px;
  border-radius: 3px;
  opacity: ${props => (props.currentStep === props.steps ? 0 : 1)};
  transition-delay: 2s;
`;

Check out the demo here: https://codesandbox.io/s/mq51n0jmrp

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

Using an if statement to run a script in Npm

Is there a way to configure an npm run script to use different AWS accounts based on the environment? { "config": { "acc": if ({npm_config_env} == "dev") "account1" else "account_2" }, "scr ...

Turned off jquery on a specific div in order to resolve compatibility problems with Vue.js

Currently, I am working on a Drupal project which includes JQuery in all pages. We have recently introduced Vue.js for creating dynamic components directly in the HTML pages (not for building a single-page application). However, we are facing an issue whe ...

Looking for a reliable CSS aggregator for .Net that can merge and minimize style sheets effectively?

Is there an open source or free project that offers a CSS manager? I want to optimize performance and am hoping to find a pre-built solution rather than starting from scratch. Some key features I'm looking for include: Merging multiple .css files in ...

The JQuery CSS function is unable to alter the height of the element

I am working with a grid that contains various elements, each with the class item. When I click on one of these elements, I toggle the class expand to resize the element. <body> <div class="grid"> <a href="#"> < ...

Unable to get the sublocality dropdown list to cascade properly in asp.net mvc

I am dealing with three dropdown lists. The initial action method for the City dropdown is shown below: public ActionResult Create() { List<SelectListItem> li = new List<SelectListItem>(); li.Add(new Sel ...

Ways to update component state using local storage data prior to rendering the component

I am currently working on developing a browser extension that involves a countdown timer. One issue I encountered is that browser extensions reload every time the user closes and reopens the popup window. To tackle this, I implemented localStorage to maint ...

The map fails to load on the HTML page

I am struggling to load a map into my HTML page from a file located in the app folder. Despite using the correct code for inserting the map, it still does not load properly. <!-- Contact section start --> <div id="contact" class="contact"> ...

Is my React-Redux state failing to update properly due to potential mutation of reducer arguments?

Appreciate your attention with what I perceive as a simple question. I'm currently working on my first "full-stack" application and encountering a challenge with React-Redux. The project involves users submitting band name ideas and voting on submissi ...

Alter the background color of a div contingent on the checkbox being checked within

I am in search of a solution to modify the background color of a parent div that contains a checkbox. The condition is that the background color should only change when the 'checked' attribute is present within the tag. HTML <div class="comp ...

An incorrect object was removed from the array

Having an issue where the wrong item is getting deleted from an array in my component's state. Here is a simplified version of my parent Component: export default class BankList extends Component { state = { banks: [new Bank("Name1"), new ...

What is the best way to extract text from a list item in an unordered list (

I am trying to search a ul list that populates a ddSlick dropdown box. ddSlick adds pictures to list items, making it a visually appealing choice. To see more about ddSlick, you can visit their website here: Here is the code I am using to loop through the ...

Checking the list box and radio button using JavaScript based on their respective IDs

Looking to validate the selection of a listbox and radio button using their respective IDs when a submit action occurs. When testing in the browser, no alert is being displayed. The goal is to trigger the script upon clicking the submit button to verify ...

jQuery Filter for Page Content - choose specific text within paragraphs and clickable links

I recently created a page search filter using Bootstrap 5, but it seems to only display text content and not any content enclosed within the a tags. You can check out the JS Fiddle link provided below for reference: https://jsfiddle.net/mfen723/rozy16pt/1 ...

When attempting to evaluate JSON data on a specific computer, the function JSON

Something strange is happening and I can't seem to figure it out, causing a big issue for me. I am currently working on a .Net web application that utilizes JSON (not json2) along with other JS libraries. In one specific proxy, the function JSON.eval ...

Issues with React's onSelect event functionality are persisting

Is there an event handler in React for the onSelect statement? For example, when a user highlights some text within a paragraph using their mouse, is there a way to trigger an event that extracts the highlighted text? import React, { Component } from &apo ...

Altering the placement of a single element from floating to fixed positioning in CSS

Currently in the process of designing a basic website, I am looking to modify the behavior of the navigation bar on the left-hand side. I want it to remain fixed in its position so that users can scroll through the page without losing sight of it. My main ...

Is it possible to string together requests in a Vue method?

Whenever a user clicks on a specific button, a request is sent to the server and an answer is received. If the user clicks on this button 100 times, I want to send 100 consecutive requests to the server. Each request must be sent after the previous one, as ...

Before the async function, make sure to set the value using React's useState

Exploring the world of react context api for the very first time. Below is my react code utilizing the context api: const [valChanged, setValChanged] = useState(false); async function modalSave() { await setValChanged(true); // STEP 1 await o ...

Bluebird Enthusiastically Predicting the Outcome of a Complex Operation

Lately, I've been heavily utilizing Bluebird in my HAPI API development. However, I've encountered a perplexing issue that has left me puzzled due to either my understanding or lack of experience. Below is an example demonstrating the challenge ...

How can we rearrange the newly added row from onRowAdd in Material Table to be displayed at the beginning of the section?

Title. According to the documentation for material table, when using editable with onRowAdd, the new row is always added at the bottom of the section. Is there a way to have it appear at the top instead? Alternatively, how can I add an onClick effect so t ...