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 3497370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:21:44+00:00 2026-05-18T12:21:44+00:00

Im really stuck. I want a CSS animation I have created (below) to activate

  • 0

Im really stuck. I want a CSS animation I have created (below) to activate on clicking a div. The only way I thought I could do that was using javascript to create an onClick event. However I dont know how to run/refrence the animation that is in my css file. Can anyone help me?

This is the animation in my css file that I want to run by clicking on a div.

@-webkit-keyframes colorchange {
 0% {
   background-color: red;
   opacity: 1.0;
   -webkit-transform: scale(1.0) rotate(0deg);
 }
 33% {
   background-color: blue;
   opacity: 0.75;
   -webkit-transform: scale(1.1) rotate(-5deg);
 }
 67% {
   background-color: green;
   opacity: 0.5;
   -webkit-transform: scale(1.1) rotate(5deg);
 }
 100% {
   background-color: red;
   opacity: 1.0;
   -webkit-transform: scale(1.0) rotate(0deg);
 }
}

I even tried putting the css in the same file as the javascript (index.html) and used the following code to try and activate it on click, but no luck.

<script>
function colorchange( test )
{
test.style.webkitAnimationName = 'colorchange ';
}
</script>

Please help 🙂

  • 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-05-18T12:21:45+00:00Added an answer on May 18, 2026 at 12:21 pm

    You’re missing the duration and you have a trailing space in the name you assign:

    function colorchange( test )
    {
        test.style.webkitAnimationName = 'colorchange'; // you had a trailing space here which does NOT get trimmed
        test.style.webkitAnimationDuration = '4s';
    }
    

    Some more infos on @-webkit-keyframes:
    http://webkit.org/blog/324/css-animation-2/

    update

    Some working code.

    <html>
        <head>
        <style>
        @-webkit-keyframes colorchange {
         0% {
           background-color: red;
           opacity: 1.0;
           -webkit-transform: scale(1.0) rotate(0deg);
         }
         33% {
           background-color: blue;
           opacity: 0.75;
           -webkit-transform: scale(1.1) rotate(-5deg);
         }
         67% {
           background-color: green;
           opacity: 0.5;
           -webkit-transform: scale(1.1) rotate(5deg);
         }
         100% {
           background-color: red;
           opacity: 1.0;
           -webkit-transform: scale(1.0) rotate(0deg);
         }
        }
        </style>
    
        <script>
        function colorchange(e) {
            if (e.style.webkitAnimationName !== 'colorchange') {
                e.style.webkitAnimationName = 'colorchange';
                e.style.webkitAnimationDuration = '4s';
    
                // make sure to reset the name after 4 seconds, otherwise another call to colorchange wont have any effect
                setTimeout(function() {
                    e.style.webkitAnimationName = '';
                }, 4000);
            }
        }
        </script>
        </head>
    
        <body>
            <div onclick="colorchange(this)">Hello World!</div>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know HTML&Css, Little Javascript & Little PHP. I really want to get in
I'm really stuck here. I have 2 issues at once: First, my site is
Really stuck on trying to write code to unzip a file or directory on
I'm stuck in having to write a simple spam filter I'm not really sure
I am stuck! this seems really daft but I can not see where I
I really want to write .NET apps that run on any platform (PC, Linux
Sadly, CSS outline isn't supported in IE7, so i'm stuck using border. But adding
I started developing with Titanium and now I really stuck on one part. I
I find myself stuck in something I think would be really easy to solve.
Guys i'm really embaraced to ask for this, but i got stuck and i

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.