Is there a way to create a smooth opacity animation for a background image?

https://i.sstatic.net/PuxYm.jpg

I am attempting to create a simple animation on my header using pink red lines that I want to make disappear and reappear on a keyframe. However, when I apply my styles, the entire container is animated instead of just the pink lines. I only want the animation to be applied to the pink lines specifically. Below is my code:

HTML

<div class="row m-0 section-1 position-relative">
      <div style="background-color: #da2f9c;" class="col-12 col-md-5 pt-5 text-center mb-5 ">
      </div>
      <div id="header" class="col-12 col-md-7 position-relative">
        <img class="img-fluid position-absolute" src="./assets/img/header/1.png">
        <img class="img-fluid position-absolute" id="pc-base-glow2" src="./assets/img/header/2.png">
        <img class="img-fluid position-absolute" src="./assets/img/header/3.png" alt="">
        <img class="img-fluid position-absolute" id="core-down" src="./assets/img/header/4.png" alt="">
        <img class="img-fluid position-absolute" id="core-up" src="./assets/img/header/5.png">
        <img class="img-fluid position-absolute" src="./assets/img/header/6.png">
      </div>
      <div class="row position-absolute diagonal">
        <div class="col-12 p-0">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="#ffffff" fill-opacity="1" d="M0,128L1440,320L1440,320L0,320Z"></path></svg>
        </div>
      </div>
    </div>

CSS

/* Experimental header */
.section-1 {
  background-color: #1b154e;
}
#header {
  /* position: relative; */
  height: 100vh;
  background-image: url('../img/header/0.png');
  background-repeat: no-repeat;
  background-position: right bottom;
  /* background-size: contain; */
  animation-duration: 5s;
  animation-name: base-lines;
  animation-iteration-count: infinite;
}

#header img {
  /* position: absolute; */
  right: 0;
  bottom: 12%;
}

How can I apply opacity to only the pink lines?

Answer №1

Here is a suggestion for you to try out:

    #header {
        position: relative;
        height: 100vh;
    }
    #header:after {
        content : "";
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        background-image: url('../img/header/0.png'); 
        width: 100%;
        height: 100%;
        opacity : 1;
        z-index: -1;
        -webkit-animation: changeBg 5s infinite;
        animation: changeBg 5s infinite;
        animation-direction: alternate;
        background-repeat: no-repeat;
        background-position: right bottom;
        animation-duration: 5s;
        animation-name: base-lines;
        animation-iteration-count: infinite;
    }

    @keyframes changeBg {
       0%   {opacity: 0.00;}
       100% {opacity: 1.00;}
    }

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

Guide to setting up a nested vuetify navigation drawer

I am facing a scenario where I have one fixed navigation drawer with icons and another dynamic navigation drawer that should open and close adjacent to the fixed one without overlapping. The current implementation is causing the dynamic drawer to overlap t ...

Creating a function that allows for the dynamic addition of rows in Angular with

I am currently working on implementing search and filter functionality, which requires adding rows dynamically. With hundreds of fields to filter, my boss has decided to organize them in dropdown menus (such as Manager, City, and Name in this example). The ...

Issues arise when setting a delay for CSS transitions to occur due to the

I'm trying to create a scroll bar that only appears when hovered over, similar to how it works on Facebook where the scroll bar shows up slowly instead of all at once. I've tried using CSS transition delay, but it doesn't seem to be working ...

Creating Radial Fades with CSS3

Seeking guidance on creating a background similar to the one shown here using just CSS. I believe it can be done, but I struggle with CSS3. The goal is for the background to be compatible with all modern browsers, not overly concerned about support for br ...

Issue with a Jquery toggleClass function not working properly on hover

Hello everyone! I am a newbie in the community and relatively new to the world of web programming. I am encountering an issue that is really frustrating me. I attempted to use this code to add a class when hovering over the ul list element so that I can d ...

Troubleshooting AngularJS Directives' Cross-Origin Problems within Eclipse

Hello, I am facing an issue while using Angular JS in Eclipse. Specifically, when attempting to use Directives, I encounter a problem with the Cross-Origin Resource Sharing (CORS) policy when loading the Directives template in the index.html file. XMLHttp ...

Encountering a problem with AJAX 'post' method while trying to post HTML elements

Incorporating AJAX to transmit the content of a div to my C# MVC controller. The structure of the AJAX post is as follows: $.ajax({ url: '/Home/SaveContent', type: 'POST', data: { model: modelDataJson, activ ...

Guide on utilizing regular expressions to match CSS selectors

Attempting to determine if the head section in jQuery contains the font-weight:bold property within CSS. That particular property may exist in 4 different variations: font-weight:bold font-weight: bold font-weight :bold font-weight : bold Is there a way ...

Is there an improved method for toggling animations in CSS using jQuery compared to my current approach?

Looking to create a toggle effect for a dropdown box that appears and disappears when a button is clicked. var clickState = false; $("#show").on("click", function() { if (!clickState) { $(".animated").removeClass("off"); refreshElement($(".an ...

Creating a div element with a fixed size that remains the same regardless of its content

Check out the code snippet below for displaying an image and title: <div id="eventsCollapsed" class="panel-collapse collapse" ng-controller="videoController"> <div class="panel-body"> <div ...

What causes Firefox (Mobile) to zoom out of my webpage?

After launching my webpage on Google Chrome mobile (android), everything loads perfectly. However, when trying to access the site using Firefox mobile (android), most pages load in a zoomed-out view. The issue is resolved by opening the drop-down menu, but ...

Tips for altering the appearance of the material-ui slider thumb design when it is in a disabled state

Through the use of withStyles, I have successfully customized the style of the Slider: const CustomSlider = withStyles(theme => ({ disabled: { color: theme.palette.primary.main }, thumb: { height: 24, width: 24, }, }))(Slider); How ...

Capture line breaks from textarea in a JavaScript variable with the use of PHP

I need help with handling line breaks in text content from a textarea. Currently, I am using PHP to assign the textarea content to a Javascript variable like this: var textareaContent = '<?php echo trim( $_POST['textarea'] ) ?>'; ...

Saving an Echo Command in a Variable

I've set up an eye exam program and now I'm trying to figure out how to display the results only after the exam is completed. The issue is that when I echo the stored SESSION variables containing the results, they are displayed even on page refre ...

Leveraging Angular for REST API Calls with Ajax

app.controller('AjaxController', function ($scope,$http){ $http.get('mc/rest/candidate/pddninc/list',{ params: { callback:'JSON_CALLBACK' } }). success(function (data, status, headers, config){ if(ang ...

HTML: Align DIV contents next to each other without any overlap

Below are three boxes displayed. Boxes 1 and 3 appear fine, but in box 2 the text content is overlapping. The issue lies with the <div> having the class .vertical_center.grade_info which has a specific margin-left of 100px, causing the overlap. I ne ...

Designing a Dynamic Page Layout with Flexbox or Grid

I have been attempting to create this specific layout using a grid system. Unfortunately, I have not been successful in achieving the desired result with my current code snippet. Please note: The DOM Structure cannot be altered https://i.stack.imgur.com/b ...

The minimum height increases as the inner divs expand

Can you help me with the code below? html <div class="content"> <div class="col"> </div> <div class="col"> </div> <div class="col"> </div> <div class="col"> </div> ...

Learn how to transform the html:options collection into html:optionsCollection

What is the best method to transform this code snippet: <html:options collection='catList' property='catId' labelProperty='catName'> using the <html:optionsCollection> tag? ...

activate the button once valid input has been provided

How can I enable a button based on the amount entered? Let's say there is a minimum of 100 and a maximum of 200. If the user enters an amount below 100, display an error message and keep the button disabled. If the user enters an amount above 200, ...