Can @keyframes be iterated through CSS (particularly Stylus)?

Here is some Stylus code I'm working with:

for i in (1..3)
  .l:nth-child({i})
     opacity (i / 5)

When executed, the output looks like this:

.l:nth-child(1) {
opacity: 0.2;
}
.l:nth-child(2) {
opacity: 0.4;
 }
.l:nth-child(3) {
 opacity: 0.6;
}

While this output is good, I am looking to modify it so that the opacity starts at 0 and is set dynamically after using @keyframes;

@keyframes o 
0%
 opacity 0 
100%  
  for i in (1..3)
  opacity (i / 5) 

The result obtained from this approach is not what I expected:

100% {
opacity: 0.2;
opacity: 0.4;
opacity: 0.6;
}

I am unsure how to achieve my desired result, do I need to utilize a function? Thank you for your help! The desired outcome should resemble the following:

100% {
.l:nth-child(1) {
opacity: 0.2;
}
.l:nth-child(2) {
opacity: 0.4;
 }
.l:nth-child(3) {
 opacity: 0.6;
}
}

Answer №1

My approach involved the creation of a keyframe for each iteration:

for x in (1..3)
 $keyframe-name = (o- + x)
 @keyframes {$keyframe-name} 
   0% 
   100%
    opacity (x/5)

To bring it to life, I then animated as follows:

for y in (1..3)
 .l:nth-child({y})
   opacity 0
   animation (o- + y) 0.25s (y/5)s linear forwards  

Kudos to @DJDavid98 for the helpful input.

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

When anchor links (href) are incorporated within a flex layout and flex-direction is set to row, they may not function as

I've designed a website with three horizontal pages, each filling the entire screen. There's a fixed menu with links that scroll to specific pages when clicked. However, users can also scroll horizontally to navigate between screens. If two page ...

Update TinyMCE settings on the fly

On my website, I have implemented Tinymce for content editing. However, when users upload files (such as images, videos, or other files) using Tinymce, they are all uploaded to the default folder defined in the TinyMCE config.php file. The issue arises w ...

Error message: Unhandled promise rejection in Express middleware - the response variable is not defined

I am encountering an issue that says: UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): ReferenceError: response is not defined My express middleware setup looks like this (simplified): const myMiddleware = require(&apos ...

An unsolicited border encompassing an image that does not resemble a CSS border or outline within the realm of Bootstrap 4

Utilizing Bootstrap4 Cards with .PNG image sources has resulted in an unexpected border appearing. It's not a border or outline issue. https://i.sstatic.net/KHgnP.png Here is the HTML <div class="row"> <div class="col-md-3"> <d ...

I am experiencing difficulty with aligning my input boxes to the center in my React-Native

Just a heads up, this is my first time diving into the world of React Native, so bear with me as I try to figure things out. Please be kind if my question seems silly... Here's a snapshot of what I currently have: https://i.stack.imgur.com/VWGFm.png ...

Running tests using gruntJS is a simple process that involves setting up your

Interested in learning how to execute the test suite using gruntjs? I initially assumed it would be easy and clear-cut, but I encountered some challenges :) I presumed that simply typing "grunt test" would suffice for running tests in gruntjs. However, th ...

What is the best way to structure Vue.js components for optimal organization?

Imagine having an index page called index.vue consisting of various components like this: index.vue <template> <div> <component-1 /> <section class="section-1"> <div class="container section-container"> <com ...

Hover over the image with some padding placed around it to see

I am struggling to figure out how to add padding to my image when hovering over it with Onmouseover. I have tried multiple solutions but none seem to be working. Here is the original code: <img src='/wp-content/uploads/2015/04/img-white.png' ...

Utilizing conditional statements and time to dynamically alter the class of an object

I need to change the class of an object based on the time, with two classes available: recommendedspot and notrecommended. The code I've written so far is not displaying the image correctly. Can someone help me troubleshoot this issue? Here is my cur ...

Place elements at the bottom of a webpage on any browser or device with just a single page

I am in the process of creating a website that features a top menu and a background image with text on the home page, covering the full screen. However, I also need to include 3 blocks at the bottom of the screen that should display consistently across all ...

Should each of them be opened in a new connection if web and worker processes are separated?

In my current NodeJS web app project, there are two processes in play - a web process and a worker process. These processes communicate via AMQP. To start the application, I run two scripts: one for the web process called server.js, and another for the wor ...

Issue: The client did not request the specified protocol. Problem detected in Flutter and Node Web Socket

I have a project with flutter code and a node backend that need to communicate via socket connections. To facilitate this, I set up a socket client in my Flutter application and a socket server in NodeJS. Unfortunately, when attempting to establish the con ...

The use of "app.use("*") appears to be triggering the function repeatedly

app.use("*", topUsers) is being invoked multiple times. The function topUsers is called repeatedly. function topUsers(req, res, next){ console.log("req.url", req.url) findMostUsefullReviewsAggregate(6) .then(function(aggregationResult){ ...

Using CSS to style PHP function results

I am working on a shopping cart application and I want to incorporate a condensed version of the cart onto my home page. The main shopping cart page is called 'modcart.php' and I have managed to integrate it into my homepage using the following c ...

Stopping a node.js server using the yarn package manager

On my PC, which runs Windows (referred to as "pc"), I have a server running Ubuntu (known as "server"). I installed Visual Studio Code and accessed the server using the vscode extension for remote development. From the vscode terminal on the server, I in ...

Is the use of div:after content really affecting the width? I am having trouble getting my transition to work

Here is a simple code snippet that represents my actual code: #myDiv { background: black; color:white; float:left; min-width:45px; max-width:450px; -webkit-transition: all 1s ease-in-out; transition: all 1s ease-in-out; } #myDiv:hover:after { width ...

Error: Unable to retrieve the name of the element because it is undefined

After updating to the latest version of NEXTUI, I encountered a new issue. Whenever I click on a NEXTUI Button that is nested within a Link from Next.js, I receive an error message stating: TypeError: Cannot read properties of undefined (reading 'node ...

The use of res.send(status, body) in Express is now deprecated, as it does not work even after making changes to the expression. It is recommended

I'm encountering an issue while attempting to return a JSON in response to my Express App POST request. The error message I received is "express deprecated res.send(status, body): Use res.status(status).send(body)", despite making the suggested chang ...

Launching the Node.js application on Heroku resulted in encountering an issue: "Application error - There was a problem within the application

When I access the browser using http://localhost:8080/, I can see the message Hello World with Express. I am currently trying to deploy this application on Heroku. I have followed the tutorial provided by Heroku. 1) Create a new app 2) Choose an App name ...

Change the class of each item in a list individually by hovering over them with the mouse using JavaScript

How to toggle classes in a list item one by one using the mouseover event in JavaScript? const items = document.querySelectorAll("ul li"); let currentItem; for (const item of items) { item.addEventListener("mouseover", e => { currentItem &am ...