Is there any way to restart a CSS3 animation when clicked without using JavaScript?
-
@JanDvorak That was quick, but not the answer I was hoping for! ;) I didn't think so, either, but I thought maybe someone else knew of some way to do it.BenjiWiebe– BenjiWiebe2013-01-09 21:18:22 +00:00Commented Jan 9, 2013 at 21:18
-
I can upvote; luckily there will come a person to prove this impossible ;-)John Dvorak– John Dvorak2013-01-09 21:22:43 +00:00Commented Jan 9, 2013 at 21:22
-
do you have a fiddle for an example HTML+CSS3 Animation to see what you have?Bastian Rang– Bastian Rang2013-01-09 21:29:28 +00:00Commented Jan 9, 2013 at 21:29
-
@BastianRang I'm messing around in the Tryit Editor on w3schools.com. This w3schools.com/css3/tryit.asp?filename=trycss3_animation3 is the animation I am using.BenjiWiebe– BenjiWiebe2013-01-09 21:36:38 +00:00Commented Jan 9, 2013 at 21:36
2 Answers
there is a css-trick summarizing some methods of doing this. You can try the :target pseudo-class instead of the checkbox-hack.
Edit:
Made a fiddle of the example using the :target pseudo-class.
3 Comments
div:target. A link to your div-id does the rest.You could do it with the Checkbox Hack though it generally isn't encouraged.
Might be worth looking into however. It is an intriguing use of html and css.
EDIT
After a bit of play, I came up with this example. The hardest part is actually just resetting the animation without javascript, not registering the click event. To get around it I duplicated the animation to a second css rule that begins when the checkbox is hit.
There may be a better way to do it, but this would theoretically work, aside from being a bit unconventional :)