Creating sequential hover animations with CSS in HTML

I have a total of four divs that I want to hover continuously, one after the other. Here is the code I am currently using:

#rij1 .content-overlayz,
#rij1 .content-details {
  animation-duration: 2s;
  animation-name: stepped-pulse;
  animation-iteration-count: infinite;
  /* animation-direction: alternate; */
  animation-timing-function: steps(4, end);
}

@keyframes stepped-pulse {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    opacity: 1;
  }
}
<a href="<?php echo base_url()?>homecontroller/types/<?=$subz->id?>">
      <div class="ProductBlock" id="rij<?=$i?>">
        <div class="contentme">
        <div class="content-overlayz"></div>
          <div class="img-fill">
            <img src="<?php echo base_url()?>admin/uploads/types/<?=$subz->pimage?>">
          </div>
          <div class="content-details" style="z-index:99">
          <h3><?=$subz->name?></h3>
      </div>
        </div>
      </div> </a>

To achieve this animation effect for the first section, I utilized the following CSS:

#rij1 .content-overlayz,
#rij1 .content-details {
  animation-duration: 2s;
  animation-name: stepped-pulse;
  animation-iteration-count: infinite;
  /* animation-direction: alternate; */
  animation-timing-function: steps(4, end);
}

@keyframes stepped-pulse {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    opacity: 1;
  }
}

Now, I am looking for assistance on how to make the remaining elements animate in the same sequence, where each section animates and then stops before the next one begins. Any help or guidance on achieving this would be greatly appreciated. Thank you in advance.

Answer №1

Ooops: It appears that you are applying styles directly to an id that is dynamically generated in your code, which may cause issues with later styling applications.

Solution: Consider adding the styling to the ProductBlock class or creating a new class if it will be used elsewhere in your project.

$(document).ready(function() {
  function playAnimation() {
    let currentIndex = 0;
    $(".ProductBlock").each(function(index) {
      let element = $(this);
      setTimeout(function() {
        $(".ProductBlock").removeClass("animateThis");
        element.addClass("animateThis");
        currentIndex++;
        if (currentIndex === $(".ProductBlock").length) {
          setTimeout(function() {
            currentIndex = 0;
            playAnimation();
          }, 2000);
        }

      }, index * 2000);
    });
  }
  playAnimation();
});
.animateThis .content-overlayz,
.animateThis .content-details {
  animation-duration: 2s;
  animation-name: stepped-pulse;
  animation-iteration-count: infinite;
  animation-timing-function: steps(4, end);
}

@keyframes stepped-pulse {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    opacity: 1;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="">
  <div class="ProductBlock" id="rij1">
    <div class="contentme">
      <div class="content-overlayz"></div>
      <div class="img-fill">
        <img src="">
      </div>
      <div class="content-details" style="z-index:99">
        <h3>
          Name 1
        </h3>
      </div>
    </div>
  </div>
</a>

<a href="">
  <div class="ProductBlock" id="rij2">
    <div class="contentme">
      <div class="content-overlayz"></div>
      <div class="img-fill">
        <img src="">
      </div>
      <div class="content-details" style="z-index:99">
        <h3>
          Name 2
        </h3>
      </div>
    </div>
  </div>
</a>

<a href="">
  <div class="ProductBlock" id="rij3">
    <div class="contentme">
      <div class="content-overlayz"></div>
      <div class="img-fill">
        <img src="">
      </div>
      <div class="content-details" style="z-index:99">
        <h3>
          Name 3
        </h3>
      </div>
    </div>
  </div>
</a>

<a href="">
  <div class="ProductBlock" id="rij4">
    <div class="contentme">
      <div class="content-overlayz"></div>
      <div class="img-fill">
        <img src="">
      </div>
      <div class="content-details" style="z-index:99">
        <h3>
          Name 4
        </h3>
      </div>
    </div>
  </div>
</a>

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

Optimizing the Placement of Dynamic Google Maps

After setting up a responsive Google map using this jsFiddle and guidance from this stack overflow post, I encountered an issue. How can I keep the map centered on the marker across various viewports and browser sizes? I came across a solution in this res ...

The issue persists with the $slice function in MongoDb

I am attempting to retrieve records using an aggregate function in MongoDB, but I keep encountering the error message stating that the operator $slice is invalid: db.getCollection('test').aggregate( [ { $match: { 'subjectId': &apos ...

Add a font awesome icon dynamically using JavaScript

I'm currently working on a navigation bar in JavaScript that displays the titles of various links. However, I would like to enhance it by adding small icons next to the text. Can anyone guide me on how to integrate Font Awesome icons into my JavaScrip ...

npm installs a multitude of dependencies

Recently, I purchased an HTML template that includes various plugins stored in a directory named bower_components, along with a package.js file. While trying to add a new package that caught my interest, I opted to utilize npm for the task. Upon entering ...

Looking for assistance with extracting only numerical values from a webpage using Selenium in Python

Website Elements <td style="font-size:20px;font-family:LucidaGrande,tahoma,verdana,arial,sans-serif;padding:10px;background-color:#f2f2f2;border-left:1px solid #ccc;border-right:1px solid #ccc;border-top:1px solid #ccc;border-bottom:1px solid #ccc; ...

Struggling to understand the relationship between SetInterval and closures

Is there a way to continuously update the contents of a div using setInterval I found inspiration from this question on Stack Overflow: How to repeatedly update the contents of a <div> by only using JavaScript? However, I have a couple of questions ...

Start by creating a set of vertices and triangles to be utilized by the vertex shader

After experimenting with vertexshaderart.com, I'm eager to apply what I've learned on a different website. While I have experience using shaders in the past, some effects achieved on the site require access to vertices, lines, and triangles. Pass ...

Despite utilizing overflow and wrap properties, HTML lists still fail to display horizontally

Make sure to copy the code and run the HTML file first. For organization, place the JavaScript file in the scripts folder and the CSS file in the styles folder. The issue at hand is that the li elements are not displaying horizontally as intended; they n ...

Issue with Ajax communication to PHP script causing data not to be sent

I am developing a web application that functions as an extensive form which will later be converted into a PDF document. Upon submission of the form, all input data is sent to a PHP file where they are stored as variables to be included in the PDF. Some of ...

Completing online form text entries in WebView without the need for identifying elements

I am currently working on a project to automate filling out an online login form using local string variables. This is the progress I have made so far: web = (WebView) findViewById(R.id.webview); WebSettings webSettings = web.getSettings() ...

Create various designs for a section of a webpage

My goal is to create a coding playground using flex-box to position different panels. Here is an example in JSBin, with the following html code: <div class="flex-box"> <div class="col" id="html-panel"> <p>html</p> </div& ...

Exploring the crossroads of MongoDB, Mongoose, and Node.js: An in-depth look

Searching for ways to retrieve references in MongoDB using Node.js and Mongoose. After reading the documentation, I discovered that there are two options available: Manual References or DBRefs. Given that Manual References are recommended, I proceeded to ...

Utilize the jQuery ajax post method within each loop to handle asynchronous requests, ensuring that the

I am currently working on a jQuery ajax function that is embedded within an each function as it needs to be executed for each post on the website. $('.post .button').each(function() { $(this).click(function() { $.ajax({ url: 'action ...

Link scripts can sometimes cause issues with node.js

Greetings! I have successfully created a client-side SPA using vanilla-router. However, my Node.js server sometimes encounters an error when attempting to load a linked script. Uncaught SyntaxError: Unexpected token '<' This error only oc ...

Exploring different methods to locate a random ID using XPATH, CSS path, and selector while conducting Selenium c# testing on a CMS tool

Issue: Hey there, I'm currently working on testing a CMS tool with selenium in C#. The problem I'm facing is finding a suitable selector for a small drop-down button due to the random generation of IDs for all selectors. Every time the script run ...

Leverage the specific child's package modules during the execution of the bundle

Project Set Up I have divided my project into 3 npm packages: root, client, and server. Each package contains the specific dependencies it requires; for example, root has build tools, client has react, and server has express. While I understand that this ...

Tips for obtaining the dynamically loaded HTML content of a webpage

I am currently attempting to extract content from a website. Despite successfully obtaining the HTML of the main page using nodejs, I have encountered a challenge due to dynamic generation of the page. It seems that resources are being requested from exter ...

Tips on incorporating a repeating gradient instead of a linear gradient

I have the following code for a linear-gradient. Click here to view the code Is there a way to modify it to use a repeating gradient instead? The goal is to maintain the same image but with a repeating gradient effect. background-image: repeating-linear ...

Retrieving Data from an Unnamed HTML Table using Selenium

I'm currently exploring ways to extract the output generated by this website: mailtester.com upon inputting a complete email. Let's take the email address [email protected] for demonstration. Once this address is entered and submission is ma ...

Dealing with a jQuery/Javascript/AJAX response: sending a string instead of an integer as a parameter to a

Trying to figure out how to handle passing integers as strings in JavaScript within an AJAX response. Here is the code snippet: message+="<td class='yellow' onclick='open_flag("+i+j+")'>"; The message variable is eventually inse ...