I would like my animation to not stop at 50%, how to avoid this short iterruption?
#-webkit-keyframes PLAY {
0% {
-webkit-transform: translate(0px,0);
}
50% {
-webkit-transform: translate(-60px,0) rotate(-1080deg) scale(2);
}
100% {
-webkit-transform: translate(-120px,0) rotate(-2060deg) scale(1);
}
}
.play {
-webkit-animation-name: PLAY;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: ease-out;
}
I think right now it's using ease-in-out, or something similar, for its "timing function".
Try adding this CSS property:
-webkit-animation-timing-function: linear;
2ND EDIT: So now that I see your class declaration it seems the easing is intentional. Since that applies to each phase of the animation though, it needs to be applied a little differently. Here's my full change - you might as well remove the timing function inside of the class:
#-webkit-keyframes PLAY {
0% {
-webkit-transform: translate(0px,0);
-webkit-animation-timing-function: ease-in;
}
50% {
-webkit-transform: rotate(-1080deg) scale(2);
-webkit-animation-timing-function: ease-out;
}
100% {
-webkit-transform: rotate(-2060deg) scale(1);
}
}
1ST EDIT: Actually, having admired your "Meanwhile, at the batcave...!" animation in my test page for a moment, I think there's a bit more to improve. I'm guessing that the translation is meant to offset the off-center spinning caused by the default "center point" position. So, you can add this CSS property, and remove the translations. Then it's not even dependent on image size.
transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-webkit-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
In fact, the 0% can just be "-webkit-transform: none"
Changed to use the correct cross-browser CSS property
Related
I created this SVG and put in some inline CSS to create a hover effect but it doesn't work. The dashed circle doesn't move and rotate, it only changes opacity. In addition, there's no transition on mouse out like normal css transition. How can I fix this ?
.wrap:hover .dash {
opacity: 0.2;
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
transform: translateX(10px);
-webkit-transform: translateX(10px);
transform-origin: 50% 50%;
-webkit-transform-origin: 50% 50%;
transition: 0.3s linear;
}
The link to my code fiddle: http://jsfiddle.net/7s4vszu3/1/
There are a couple of issues here:
First, your transition and transform-origin should be set without the hover selector. This is the reason you weren't seeing the proper transition on mouse out.
Second, you need to include both your transformations in the same rule, so that one doesn't overwrite the other. In your code, your translate is overwriting your rotate.
Here's what it should look like:
.wrap .dash {
transform-origin: 50% 50%;
-webkit-transform-origin: 50% 50%;
transition: transform 1s linear, opacity 1s linear;
}
.wrap:hover .dash {
opacity: 0.2;
transform: rotate(90deg) translateX(10px);
-webkit-transform: rotate(90deg) translateX(10px);
}
Example here: http://jsfiddle.net/unc3re9b/
So I have this cute little spinner made to signify when something is loading. The perspective changes and the background color are supposed to change at the same time. I am having trouble getting the Transform and Transition timings to line up so that you don't see the color change, it needs to be already changed when the square flips so that it is a smooth transition.
Link to JS Fiddle
HTML
<div class="spinner"></div>
CSS
.spinner {
width: 20px;
height: 20px;
-webkit-animation: rotateplane 1.2s infinite ease-in-out;
animation: rotateplane 1.2s infinite ease-in-out;
}
#-webkit-keyframes rotateplane {
0% { -webkit-transform: perspective(120px); background-color: #00b16a; }
50% { -webkit-transform: perspective(120px) rotateY(180deg); background-color: #f22613;}
100% { -webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg); background-color: #aaabae; }
}
#keyframes rotateplane {
0% {
transform: perspective(120px) rotateX(0deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg)
} 50% {
transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
-webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg)
} 100% {
transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
-webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
}
}
Two things to consider:
Transitions interpolate smoothly (well, according to the easing function) between keyframes.
If you do not specify an attribute at a keyframe, it will interpolate without interruption over that keyframe.
With those in mind, you can change the keyframes to apply your color change in the middle of your perspective change. In addition, you'll set two keyframes for the color change, very close to each other, to ensure the interpolation happens over a small time slice.
#-webkit-keyframes rotateplane {
0% { -webkit-transform: perspective(120px); background-color: #00b16a; }
24.9% {background-color: #00b16a;}
25.0% {background-color: #f22613;}
50% { -webkit-transform: perspective(120px) rotateY(180deg); background-color: #f22613;}
74.9% { background-color: #f22613; }
75% { background-color: #aaabae; }
100% { -webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg); background-color: #aaabae; }
}
Now, you'll notice that since you have the animation on infinite repeat, that you still get a color transition when the animation loops from 100% to 0%. You'll have to either specify animation-direction: alternate; or adjust your keyframes so that 100% ends at a reasonable tweening point between 100% and 0%.
DEMO using alternate
I can't understand how to run animation for some constant period of time.
Here is the source of animation:
#-webkit-keyframes pulse {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
50% {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
.pulse {
-webkit-animation-name: pulse;
}
So I modify css of the element where I want apply pulse.
-webkit-animation-duration: 10s;
-webkit-animation-delay: 0s;
-webkit-animation-iteration-count: 10;
As I understand docs, the animation should be run 10 times for 10s each. So, 100 seconds at all. But this is wrong. What is the right way to specify animation life as 100 seconds?
Ok, so you say that the timing function you are getting is incorrect, well I won't agree to that, when you are setting an animation duration to 10s that means, 5s for first cycle, and in the next 5s for your div to scale out.
I am using JavaScript count down here, and am also using animation-delay property set to 1 seconds, just to sync with JavaScript countdown which I took from here...
So if you see, the animation ends perfectly at 1 so it works perfectly, if you are expecting to do something else than please comment and I will modify my answer accordingly..
Demo (I've reduced the animation iteration to 2 = 20 seconds)
Note: Use Chrome to see the Demo as OP is using only -webkit and
haven't requested any code for Firefox or Internet Explorer.
#-webkit-keyframes pulse {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
50% {
-webkit-transform: scale(2);
transform: scale(2);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}
.pulse {
-webkit-animation-name: pulse;
-webkit-animation-duration: 10s;
-webkit-animation-delay: 1s;
-webkit-animation-iteration-count: 2;
position: absolute;
left: 50%;
font-size: 50px;
top: 10%;
}
I would like to start the animation (the first time) from the current position.
the openAnimation goes from the point A to point B and the closeAnimation goes from the point B to the point A.
So, at page loading, the animation is suppose to be in the point B.
but when for the first time I change the class, the div starts from the point A.
#-webkit-keyframes openAnimation
0%
-webkit-transform: translateX(300px)
100%
-webkit-transform: translateX(0px)
#-webkit-keyframes closeAnimation
0%
-webkit-transform: translateX(0px)
100%
-webkit-transform: translateX(300px)
in the .open class
-webkit-transform-origin: 100% 50%
-webkit-animation: openAnimation 1s both ease-in
in the .close class
-webkit-transform-origin: 100% 50%
-webkit-animation: closeAnimation 1s both ease-in
what can I do for don't see the animation the first time?
You probably want transition, not animation. For example, see http://jsfiddle.net/g9dn1a09/
Basically you want following CSS:
.box {
transition: transform 1s;
}
.close {
transform: translateX(300px);
}
.open {
transform: translateX(0px);
}
Note that you want transition defined with a selector that is always applied. If you change property transition using .close or .open class selectors in the middle of the transition (animation) it will look bad.
I put this up on jsfiddle. Chrome/Safari only until you add more vendor prefixes or opt to go with a prefixfree.js or other option.
.open {
-webkit-transform-origin: 100% 50%;
-webkit-animation: openAnimation 1s both ease-in;
}
.close {
-webkit-transform-origin: 100% 50%;
-webkit-animation: closeAnimation 1s both ease-in;
}
#-webkit-keyframes openAnimation {
0% {
-webkit-transform: translateX(0px);
}
100% {
-webkit-transform: translateX(300px);
}
}
#-webkit-keyframes closeAnimation {
0% {
-webkit-transorm: translateX(300px);
}
100% {
-webkit-transform: translateX(0px);
}
}
http://jsfiddle.net/LtJLc/
I would like to keep the left edge of div.box in the same place during a transformY(-180deg) animation. I can't understand why is it moving. This is the code:
transform-origin: 0% 0%;
transform: rotateY(-180deg);
And here is the live example http://dabblet.com/gist/5551520
You're also transitioning the transform-origin, as you use transition: all, and it is specified in the hover state. The initial value is to be centred.
If you put transform-origin: 0% 0%; on .box it will work as expected.
.box {
/* removed additional styles */
transition: all 600ms linear;
transform-origin: 0% 0%;
}
body:hover .box {
transform: rotateY(-180deg);
}
http://dabblet.com/gist/5551730