0

I want some animation to be triggered to onclick of an element only using pure css. I have already assigned keyframe to this class container. There is a tag So when I click this, container's animation get started. Is it possible without using jquery ? In simple words when button is clicked animations get started with the assigned keyframe.

HTML

<div class="container container-anim">
   <div class="psw align-self-center">
       <a style="color:maroon" href="#reset">Back to log-in page</a> 
   </div>
</div>

CSS

.container-anim {    
animation-name: stretch;    
animation-duration: 1.5s; 
animation-iteration-count: infinite;

}

@keyframes stretch {
0% {transform: scale(1);}
50%{ }
100%{transform: scale(1.2);}

}

2 Answers 2

1

There is no way that I know off to trigger animation without using some sort of JS to attach the class to the div element.

I would just use an onclick and jquery (or vanilla js)

<div class="container" onclick="$('.container').addClass('container-anim');">
   <div class="psw align-self-center">
       <a style="color:maroon" href="#reset">Back to log-in page</a> 
   </div>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer but there's a restriction as mentioned in the question already
0

An approach you can try is using the :active pseudo-class, this plays your animation when you click on any element. as so:

.container-anim:active {    
animation-name: stretch;    
animation-duration: 1.5s; 
animation-iteration-count: infinite;

}

@keyframes stretch {
0% {transform: scale(1);}
50%{ }
100%{transform: scale(1.2);}
}
<div class="container container-anim">
   <div class="psw align-self-center">
       <a class="a" style="color:maroon" href="#reset">Back to log-in page</a> 
   </div>
   </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.