Is there a way to initiate a background fade-in once an animation has finished?

I have customized the background of the parent element called "banner".

Is there a way to smoothly fade in this background after the child elements "block" and "block2" finish animating and reveal the underlying text?

<section id="banner">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 col-md-12 col-sm-12">
        <div class="box bg">
          <!-- Start of intro animation container --->
          <div class="title">
            <!-- Start of main heading --->
            <span class="block"></span>
            <h1 class="home-header second-header">WORN WAX<span class="dot2">.</span></h1>
          </div>
          <!-- End of main heading --->
          <div class="role">
            <!-- Start of sub heading --->
            <div class="block2"></div>
            <p class="role-text project-type">WEBSITE BUILD / APP DESIGNS</p>
          </div>
          <!-- End of sub heading --->
        </div>
        <!-- End of intro animation container --->
      </div>
    </div>
  </div>
</section>

Answer №1

This innovative CSS-only method utilizes keyframe animation to achieve a stunning effect. By determining the duration of the initial animation (I opted for a fade-in effect as an example), you can use that timing as a delay to gradually reveal the background. It's important to apply the background image on a pseudo-element so that lowering the opacity doesn't render everything inside the element invisible, including its child elements like .title and .role.

.home-header,
.project-type {
  width: 200px;
  text-align: center;
  color: white;
  background-color: darkred;
  margin: 1rem auto;
  padding: 1rem;
  -webkit-animation: fadein 2s;
  /* Safari, Chrome and Opera > 12.1 */
  -moz-animation: fadein 2s;
  /* Firefox < 16 */
  -ms-animation: fadein 2s;
  /* Internet Explorer */
  -o-animation: fadein 2s;
  /* Opera < 12.1 */
  animation: fadein 2s;
}

.box.bg {
  padding: 2px;
  position: relative;
}

.box.bg::after {
  content: "";
  opacity: 0;
  background-color: lightgreen;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  position: absolute;
  z-index: -1;
  /* Delay until after the block animations */
  -webkit-animation: fadein 2s ease 2s;
  /* Safari, Chrome and Opera > 12.1 */
  -moz-animation: fadein 2s ease 2s;
  /* Firefox < 16 */
  -ms-animation: fadein 2s ease 2s;
  /* Internet Explorer */
  -o-animation: fadein 2s ease 2s;
  /* Opera < 12.1 */
  animation: fadein 2s ease 2s;
}

# Based on https: //stackoverflow.com/a/11681331/5015356
@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}


/* Firefox < 16 */

@-moz-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}


/* Safari, Chrome and Opera > 12.1 */

@-webkit-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}


/* Internet Explorer */

@-ms-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}


/* Opera < 12.1 */

@-o-keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
<section id="banner">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 col-md-12 col-sm-12">
        <div class="box bg">
          <!-- Start of intro animation container --->
          <div class="title">
            <!-- Start of main heading --->
            <span class="block"></span>
            <h1 class="home-header second-header">WORN WAX<span class="dot2">.</span></h1>
          </div>
          <!-- End of main heading --->

          <div class="role">
            <!-- Start of sub heading --->
            <div class="block2"></div>
            <p class="role-text project-type">WEBSITE BUILD / APP DESIGNS</p>
          </div>
          <!-- End of sub heading --->

        </div>
        <!-- End of intro animation container --->
      </div>
    </div>
  </div>
</section>

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

The request parameter is missing when trying to invoke methods on the MultiActionController

During the Spring 3.0 era suppose I have a jsp page with two different links, each calling a different method on MultiActionController <form:form method="POST"> <a href="user.htm?action=add" style="color: blue;">Add</a> <a hr ...

Guide on dynamically applying a CSS rule to an HTML element using programming techniques

Currently working with Angular 6 and Typescript, I am facing a unique challenge. My task involves adding a specific CSS rule to the host of a component that I am currently developing. Unfortunately, applying this rule systematically is not an option. Inste ...

Ways to retrieve text from a pdf document using JavaScript?

Is there a way to extract text from a PDF using JavaScript? I've looked into npm modules like PDF-TO-TEXT, but they require a file path name as input. I'm currently using the react-drop-to-upload module to allow users to drop PDF files onto a rea ...

Maximizing the use of JavaScript's prototype.js library: Passing parameters to callback functions

My understanding of JavaScript is limited to using it for Dynamic HTML. However, I am now exploring Ajax and facing an issue with the code below (taken from and modified to suit my requirements). I need to pass the update_id parameter to the onSubmit fun ...

Using regex pattern in mobile with HTML5 input type number

Looking to create a regex pattern for an input field with type number that only allows numbers and dots. Here's what I've tried: <input type="number" pattern="[0-9.]*"> <input type="tel"> Both options are allowing only numbers (0-9 ...

What are the steps for rearranging a table column?

I am trying to show a text file in a table and allocate some code to each entry. I can display the text file. I can assign the code for each record (though this part is still under development). However, I have encountered an issue. The columns of the t ...

Retrieve the information from all promises

Hey there, I hope you're having a great day! So, after successfully returning multiple images using multer and testing it out, I now want to access the result variable. Take a look at how I achieved this below: req.body.images = []; const images = ...

How can I include JavaScript in an HTML document?

My folder structure is as follows: Inside webapp/WEB-INF/some.jsp, I also have a javascript file located in the same directory at webapp/WEB-INF/js/myform.js. I referenced it in some.jsp like this: <script type="text/javascript" src="js/myform.js"> ...

Toggle the display of input fields based on radio button selection in Angular 2

We want to dynamically display additional input fields based on the selected radio button. Radio <div class="form-group"> <label>What would you like to evaluate?</label> <div class="radio"> <label> ...

JavaScript in an array of arrays consists of different arrays

I've been searching for a solution to this issue, but haven't been able to find one. If I have an array of arrays, is there a way to check if one of those arrays is included in the main array? While I tried using Array.prototype.includes(), it d ...

The primefaces remoteCommand tag is failing to function properly as it is unable to pass the HTML content of the current page using jQuery to the managed

Utilizing Jquery's .html() method, I am extracting the HTML of my current page in the following manner. <h:outputScript name="js/jquery-1.7.2.js" /> <h:outputScript> function fetchHtml(){ $('#next').click(function(){ ...

Dynamically loading various compositions of EDGE

I'm currently working on developing a testing system for edge-animate compositions. The goal is to be able to load different compositions and verify that they are displaying correctly, as well as make changes to their customizable fields. I attempted ...

Tips for displaying dynamic images using the combination of the base URL and file name in an *ngFor loop

I have a base URL which is http://www.example.com, and the file names are coming from an API stored in the dataSource array as shown below: [ { "bid": "2", "bnam": "ChickenChilli", "adds": "nsnnsnw, nnsnsnsn", "pdap": " ...

Is it possible to send an entire HTML table to the server and then update the database table with it?

Recently, I encountered an issue that has me stumped. Suppose I have a database table A with multiple columns and the server (PHP script) renders this data into an HTML table for the web client. Now, the challenge lies in allowing users to add/delete rows ...

Leveraging both Vuex and an Event Bus in your Vue application

For some time now, I've been pondering over this question that has been lingering in my mind. My current Vue application is quite complex, with a significant number of components that need to communicate effectively. To achieve this, I have implemente ...

The jQuery pagination feature combined with the :hover pseudo-class

Here is a link to my website: Gutdesign If you click on TV located on the left side, you will see a list of projects. Everything looks good to me, but I am having trouble figuring out how to hide the orange arrows at the start. I want them to appear only ...

Is it possible to invoke a helper function in Node.js from within a callback?

I recently started programming with node.js and I am encountering an error that I can't quite figure out. The function appears to be correctly set up, and I don't believe there are any asynchronous issues because of the self variable I have in pl ...

Achieve equal height columns when they are stacked vertically using Bootstrap 5

Can columns be equal height when they become rows on mobile devices? <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="57353838232423253627176279677965">[email protected]</ ...

Can you suggest an efficient method for routing with EJS templates on an Express server without constantly repeating code?

Assuming my app consists of two views: index.ejs and profile/index.ejs, I aim to set up routing using express code as shown below. /* GET home page. */ router.get('/', function (req, res, next) { res.render('index'); }); /* GET pr ...

Show Options at the Top of the List

With a basic <select> list containing multiple <option> elements, the goal is to have the selected option displayed at the top of the select list when shown again (currently it appears at the bottom). The project utilizes bootstrap and jQuery, ...