Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:01:33+00:00 2026-06-15T18:01:33+00:00

I have some keyframe animations in my css file. There is already an animation-delay

  • 0

I have some keyframe animations in my css file. There is already an animation-delay specified.
The wrapper div has the attribute data-delay.

I want to get the animation-delay in the css file and add the value of data-delay to it.
Then i want that the animation start with the new delay.

I tried ele[i].style.animationDelay.
But it seems that this returns null until I set a value to it.

If I set ele[i].style.animationDelay = '5s' the animation still runs with the delay of the css file.

HTML

<div id="wrapper" data-delay="2s" >
    <h1 id="hi">Hi</h1>
    <h1 id="name">test!</h1>
</div>

CSS

body { font-size: 300%; }

#wrapper h1 { position: absolute; }

#hi {
    transform: translate(-200px, 100px);

    animation-name: hi;
    animation-duration: .5s;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
    animation-delay: 0s;
}

#name {
    transform: translate(-200px, 150px);

    animation-name: name;
    animation-duration: .5s;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
    animation-delay: 1s;
}

@keyframes hi{
    100% { transform: translate(50px, 100px) };
}

@keyframes name{
    100% { transform: translate(50px, 150px) };
}

JS

var wrapper = document.getElementById('wrapper');
var ele = wrapper.children;
var delay = wrapper.getAttribute('data-delay');

for (var i=0;i<ele.length;i++) {

    alert(ele[i].style.animationDelay);
    ele[i].style.animationDelay = delay;
    alert(ele[i].style.animationDelay);
}

http://jsfiddle.net/FHuKN/4/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:01:34+00:00Added an answer on June 15, 2026 at 6:01 pm

    I’ve only tested this on Mac 10.8 Chrome 25, Safari 6.0, and FF 18.0.

    Sounds like the main thing you wanted to do was add the data-delay value to whatever existing animation delay was applied to the elements.

    HTML – unchanged

    <div id="wrapper" data-delay="5.1s" >
        <h1 id="hi">Hi</h1>
        <h1 id="name">test!</h1>
    </div>
    

    CSS – Vendor prefixes and initial keyframes (0%) were added.

    body { font-size: 300%; }
    
    #wrapper h1 { position: absolute; }
    
    #hi { 
        -webkit-transform: translate(-200px, 100px);
        -webkit-animation-name: hi;
        -webkit-animation-duration: .5s;
        -webkit-animation-timing-function: linear;
        -webkit-animation-fill-mode: forwards;
        -webkit-animation-delay: 2.1s;
    
        -moz-transform: translate(-200px, 100px);
        -moz-animation-name: hi;
        -moz-animation-duration: .5s;
        -moz-animation-timing-function: linear;
        -moz-animation-fill-mode: forwards;
        -moz-animation-delay: 2.1s;
    
        transform: translate(-200px, 100px);
        animation-name: hi;
        animation-duration: .5s;
        animation-timing-function: linear;
        animation-fill-mode: forwards;
        animation-delay: 2.1s;
    }
    
    #name { 
        -webkit-transform: translate(-200px, 150px);
        -webkit-animation-name: name;
        -webkit-animation-duration: .5s;
        -webkit-animation-timing-function: linear;
        -webkit-animation-fill-mode: forwards;
        -webkit-animation-delay: 3.1s;
    
        -moz-transform: translate(-200px, 150px);
        -moz-animation-name: name;
        -moz-animation-duration: .5s;
        -moz-animation-timing-function: linear;
        -moz-animation-fill-mode: forwards;
        -moz-animation-delay: 3.1s;
    
        transform: translate(-200px, 150px);
        animation-name: name;
        animation-duration: .5s;
        animation-timing-function: linear;
        animation-fill-mode: forwards;
        animation-delay: 3.1s;
    }
    
    @-moz-keyframes hi{
        0% { -moz-transform: translate(-200px, 100px); }
        100% { -moz-transform: translate(50px, 100px); }
    }
    @-webkit-keyframes hi {
        0% { -webkit-transform: translate(-200px, 100px); }
        100% { -webkit-transform: translate(50px, 100px); }
    }
    @keyframes hi{
        0% { transform: translate(-200px, 100px); }
        100% { transform: translate(50px, 100px); }
    }
    
    @-moz-keyframes name {
        0% { -moz-transform: translate(-200px, 150px); }
        100% { -moz-transform: translate(50px, 150px); }
    }
    @-webkit-keyframes name {
        0% { -webkit-transform: translate(-200px, 150px); }
        100% { -webkit-transform: translate(50px, 150px); }
    }
    @keyframes name {
        0% { transform: translate(-200px, 150px); }
        100% { transform: translate(50px, 150px); }
    }
    

    JAVASCRIPT

    On an element, the style property doesn’t hold all the style information because it only represents what is being set directly on the element via the style attribute. MDN

    window.getComputedStyle() seems to work pretty well.

    Juggling the prefixed properties is a little clunky, but it worked in the browsers I tested with.

    (function(undefined) {
    
        var wrapper = document.getElementById('wrapper'),
            elms = wrapper.children,
            delay = wrapper.getAttribute('data-delay'),
            prop,
            styl,
            cur,
            i;
    
        delay = !delay ? 0 : Number(delay.replace(/[^\d\.]/g, ''));
    
        if (!elms.length) {
            return;
        }
    
        styl = window.getComputedStyle(elms[0]);
    
        if (styl.getPropertyValue('animation-delay')) {
            prop = 'animation-delay';
    
        } else if (styl.getPropertyValue('-webkit-animation-delay')) {
            prop = '-webkit-animation-delay';
    
        } else if (styl.getPropertyValue('-moz-animation-delay')) {
            prop = '-moz-animation-delay';
    
        } else {
            console.log('unable to find prop');
            return;
        }
        // console.log('prop', prop);
    
        for (i = 0; i < elms.length; i++) {
            styl = window.getComputedStyle(elms[i]);
            cur = styl.getPropertyValue(prop);
            cur = Number(cur.replace(/[^\d\.]/g, ''));
            elms[i].style.setProperty(prop, (cur + delay) + 's');
    
            console.log('delay: ' + cur + 's -> ' + (cur + delay) + 's')
        }
    
    })();
    

    http://jsfiddle.net/FHuKN/11/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some slide animation in css. There is any chance to keep this
I've put together some key frame animations in CSS which animate a div from
Suppose I have a storyboard, created at runtime by some process, containing keyframe animations.
I'm trying to animate object. I use keyframe animation: I have two vertex buffers
I have some objects in an animation which are continously animating in a rotation
I have a some animation which in the end will hopefully make up a
I try to do this: There is an view which has been rotated already
I have some odd experience with my browser here. this code below already uploaded
I have some simple CSS3 animations here: http://chooseavirb.com/strat/ . They work fine on Firefox,
I have some data loaded as a np.ndarray and need to convert it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.