+ 15

How to trigger css animations on clicking

i want my div when it is clicked it should rotate.Here is the my code:-The @keyframes line is not copied;- #Booster{ height:70px; width:70px; background-color:lightgreen; border-radius:50%; position:absolute ; top:430px; left:150px; border-top:2px solid red; border-bottom:2px solid red; border-right:2px solid transparent ; border-left:2px solid transparent ; animation-name: boost; animation-duration: 1.0s; animation-iteration-count: 1; }

20th Mar 2017, 10:41 AM
Nikhil
Nikhil - avatar
7 Respostas
+ 15
Thanks both and RY what a coincidence i was just seeing your comment Krishna sir's code
23rd Mar 2017, 9:18 AM
Nikhil
Nikhil - avatar
+ 14
@Utkarsh i have to write just the animation name in #Booster:hover and not the animation delay,duration,and others??
26th Mar 2017, 2:12 AM
Nikhil
Nikhil - avatar
+ 14
@Mark your method helped and also@Utkarsh your one too .........Thanks both😊😊
26th Mar 2017, 5:12 AM
Nikhil
Nikhil - avatar
+ 9
Using Javascript. Create a class with the style declarations of how you want it rotated. When a user clicks the div, add that class to it. You wouldn't even need an animation property, just add: transition: all 1s linear; to your css block for the div #booster. #booster .rotate { transform: rotate(90deg); // what ever degree } $("#booster").on("click", function(){ this.addClass("rotate"); });
26th Mar 2017, 4:53 AM
Mark Foxx
Mark Foxx - avatar
+ 7
you can use CSS hover method put it like #Booster{ //everything as you wrote //dont put the animation name here } #Booster:hover{ animation-name:boost; } but it has one problem you have to click somewhere else first the click again to run it again it should work but i am not sure
25th Mar 2017, 6:10 PM
Utkαrsh
Utkαrsh - avatar
+ 7
@nikhil Yes , just the animation name . On clicking the object the animation will take place .
26th Mar 2017, 4:36 AM
Utkαrsh
Utkαrsh - avatar
+ 6
Apply/remove it with JavaScript....👍
23rd Mar 2017, 9:17 AM
Cory Gutierrez🔹
Cory Gutierrez🔹 - avatar