I have been having trouble understanding how css3 rotations work. I have seen many examples and tried to implent my own, but to no avail. My goal is to have a link spin a single character I.e. text >> (+) on click. What I want to achieve is to have the animation start farily slow speed up rapidly then stop all in a couple seconds or less.
I don't know if that is particularly possible with Css3, if not I will use Jquery. However I have tried to wrap my head around the keyframes thing. I know I need a kit for each browser specifically to create the animation and add the attributes. After which I need to set the rules for keyframes and rotation degrees. But every time I try to write the code I get errors almost as if it's a syntax error. (somehere in here apparently.)
#-ms-keyframes spin {
from { -ms-transform: rotate(0deg); }
to { -ms-transform: rotate(360deg); }
}
#-moz-keyframes spin {
from { -moz-transform: rotate(0deg); }
to { -moz-transform: rotate(360deg); }
}
#-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(360deg);
}
}
I have spent almost an hour looking at that specific code, not a single syntax error. If anyone that can help with my problem would I would be greatful.
Js Fiddle
This is basically what I am after but I want to click and spin it.
Reduce the duration to speed it up.
animation-duration: 2000ms;
Animation timing function will give you the faster spin near the end of the animation.
animation-timing-function: ease-in;
For this to be a bit more flexible I'd separate your animation CSS3 from the div and into its own class so you can add it on the initial click.
div.spin {
-webkit-animation-name: spin;
-webkit-animation-duration: 2000ms;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-in;
-moz-animation-name: spin;
-moz-animation-duration: 2000ms;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease-in;
-ms-animation-name: spin;
-ms-animation-duration: 2000ms;
-ms-animation-iteration-count: 1;
-ms-animation-timing-function: ease-in;
animation-name: spin;
animation-duration: 2000ms;
animation-iteration-count: 1;
animation-timing-function: ease-in;
}
You'll need to use javascript to trigger the animation on click and to restart the animation.
var $div = $("div");
$div.click(function (e) {
// restart animation
$(this).addClass("spin");
var el = $(this),
newone = el.clone(true);
el.before(newone);
$("." + el.attr("class") + ":last").remove();
});
See the full working example here
Related
I have a simple CSS3 animation which I would like to pause on hover.
Here is a simplified version:
h1 {
animation-name: test 3000ms infinite alternate;
}
#keyframes test {
from {
transform: translate(0,0);
}
to {
transform: translate(100px,0);
}
}
h1:hover {
animation: paused;
}
It works, but pausing means jumping back to the 0% state. Is there a way to either (a) pause in the current state of (b) resetting more gracefully, such as running through one final loop?
Thanks
Use animation-play-state as below:
h1 {
animation-name: test;
animation-duration:3000ms;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-play-state:running;/*running normally*/
}
h1:hover {
animation-play-state:paused; /*paused when hover*/
}
DEMO
Note - The animation-play-state property is not supported in Internet Explorer 9 and earlier versions.
Hello I am trying to animate an element so that it spins 7 times then slows down and eases I have the spinning done I just need to ease it. I am using a from and to keyframe to spin it, would I need to do it frame by frame or is there another way?
#keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(360deg);
}
}
.spin.animated {
animation-name: spin;
animation-duration: 400ms;
animation-iteration-count: 7;
animation-timing-function: linear;
}
You mean like this:
.spin {
width:100px;
height:100px;
background:red;
}
#-webkit-keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(2520deg);
}
}
.spin.animated {
-webkit-animation-name: spin;
-webkit-animation-duration: 2800ms;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
}
<div class="spin animated"></div>
Or even better:
.spin {
width:100px;
height:100px;
background:red;
}
.spin:hover {
transform:rotate(2520deg);
transition: transform 3s ease-out;
}
<div class="spin"></div>
In the to, give another animation:
#keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
animation: ease;
}
}
#keyframes ease {
}
You might need to tackle the iteration count here. It should happen only after the 7 animations. So, I am not sure about that.
You have it pretty much all the way there.
.spin.animated {
animation-name: spin;
animation-duration: 400ms;
animation-iteration-count: 7;
animation-timing-function: ease; /* your timing function is where you tell it how to animate */
}
here is list of all available calls:
http://www.w3schools.com/cssref/css3_pr_animation-timing-function.asp
You can do it with a cubic bezier timing function.
Something like
cubic-bezier(0.81, 0.95, 0.84, 0.95)
will give an effect like the one that you are searching. There is a linear animation most of the time, and then it slows down
You can try different values, and set it graphically, here
bezier curve tester
I do not understand the difference between -webkit-animation and -moz-animation. What is the difference in between the two or these, or are the same?
I googled this question but couldn't find out the differences.
Here is the code example:
.blink_me {
font-size:60px;
font-weight:bold;
-webkit-animation-name: blinker;
-webkit-animation-duration: 1.5s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-moz-animation-name: blinker;
-moz-animation-duration: 1.5s;
-moz-animation-timing-function: linear;
-moz-animation-iteration-count: infinite;
animation-name: blinker;
animation-duration: 1.5s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
#-moz-keyframes blinker
{
0% { opacity: 1.0; }
50% { opacity: 0.0; }
100% { opacity: 1.0; }
}
#-webkit-keyframes blinker
{
0% { opacity: 1.0; }
50% { opacity: 0.0; }
100% { opacity: 1.0; }
}
#keyframes blinker
{
0% { opacity: 1.0; }
50% { opacity: 0.0; }
100% { opacity: 1.0; }
}
Here in this code -webkit-animation ,-moz-animation and at last the simple animation is used why these three are being used with same functionalities?
These are the vendor-prefixed properties used by different rendering engines of browsers(gecko,blink,webkit,trident etc)
-webkit for Chrome(blink,webkit), Safari(webkit) and Opera(blink);
-moz for Firefox(gecko),
-o for Opera(presto),
-ms for Internet Explorer(Trident).
Usually they're used to implement CSS features that are proprietary or the browser companies are still fighting over on the way it is supposed to be implemented, until finalisation by W3.
Using prefixes allows properties to be set to each rendering engine so you can tweak your css to adjust for the different implementations.
In theory after the inconsistencies are resolved the prefix will be removed. However there are always older versions of the browser you need to write and support CSS code for, so in practice it will take a lot of time before you can drop the prefix.
Also note that it's convention to declare the prefixed version first and then the standard version, so if and when the specifications are updated, the standard version will override the prefix versions
I would like to know how to avoid the keyframe animation to be automatically reseted after launching anoher one or visiting another tab of my browser.
#-webkit-keyframes play1 {
0% {
-webkit-transform: translate(0px,0);
}
50% {
-webkit-transform: translate(-60px,0) rotate(-1080deg) scale(1.5);
}
100% {
-webkit-transform: translate(-120px,0) rotate(-2060deg) scale(1);
}
}
.play1 {
-webkit-animation-name: play1;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
}
#-webkit-keyframes play2 {
0% {
-webkit-transform: translate(0px,0);
}
50% {
-webkit-transform: translate(-60px,0) rotate(-1080deg) scale(3);
}
100% {
-webkit-transform: translate(-120px,0) rotate(-2060deg) scale(1);
}
}
.play2 {
-webkit-animation-name: play2;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
}
On this example, if i launch the animation play1 then play2 by adding the respective classes on the elements, the position of the element accoding to the play1 animation is automatically reseted to its initial position (if i visite another tab and come back, all my elements are in their initial position), how to avoid this?
Even worse on mozilla, the animation is reseted when its over.
I don't have this behavior by using the animation-iteration-count: infinite; property, but i just want to play it one time.
The property which enables this is: animation-fill-mode: forwards
I have the CSS below that does a rotate and fade-in and it works just fine. The rotate/fade is timed just like I want it but I'd like a longer duration between the rotate/fade -- like 30s or so. If I increase duration, that slows the rotate/fade too much. How do I set the keyframes to retain the rotate/spin timing but allow 30s between the rotate/fade? I searched but couldn't find an applicable answer. Thank you very much.
#-webkit-keyframes SomeName {
0% { opacity:0; -webkit-transform: rotateY(180deg); }
50% { opacity:0; -webkit-transform: rotateY(180deg); }
75% { opacity:1; -webkit-transform: rotateY(0deg); }
100% { opacity:1; -webkit-transform: rotateY(0deg); }
}
#flipBox img.flippy {
-webkit-animation-name: SomeName;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 10s;
-webkit-animation-direction: alternate;
}
p.s. FYI: This is webkit only, hence the only prefix.
Live Demo
Use this code
animation:SomeName 5s;
-moz-animation:SomeName 5s; /* Firefox */
-webkit-animation:SomeName 5s; /* Safari and Chrome */
-o-animation:SomeName 5s; /* Opera */
Hope this will help you.