I'm trying to animate an element back and forth, with a flip at each end. I'm using a CSS animation with scaleX(-1) at the end. It works fine in everything but IE, where it's shooting the element all the way off the page, then sliding it back into position.
#keyframes moveAndFlip {
48% {
transform: translateX(12vh) scaleX(1);
}
50% {
transform: translateX(12vh) scaleX(-1);
}
98% {
transform: translateX(0) scaleX(-1);
}
}
http://jsfiddle.net/pq9yqscy/2/
Is this a known issue in IE? Another way to tackle it?
Related
I made a little CSS animation with a simple svg to transition my hamburger menu to a cross. It works as expected on Chrome and Firefox, but the translation is off in Safari. The animation plays, and even resets correctly so it has nothing to do with prefixes (I tried). The translate of the two lines making the cross is just wrong.
I'm guessing it has something to do with how safari handles the transform when scaling is also applied. Does anyone know if there is a work around / or what I'm doing wrong?
JSFiddle
Safari / Firefox / Chrome
#keyframes showCross {
0% {
transform: scale(1) rotate(0);
}
40% {
transform: scale(0.3) rotate(280deg);
}
100% {
transform: scale(1) rotate(360deg);
}
}
#keyframes showCross_P1 {
0% {
transform: rotate(0);
}
100% {
transform: rotate(-45deg) translate(-42%, -10%);
}
}
I fixed it by doing the following:
First I removed the groups surrounding the paths.
Then I gave all the paths the following values:
transform-origin:center center;
transform-box: fill-box;
Next I edited the animation keyframes to look as follows:
0% {
transform: translate(0rem,0rem) rotate(0);
}
100% {
transform: translate(-10rem,-38rem) rotate(-45deg) ;
}
Safari has problems with percents and also if you put the rotation before the translate it has inconsistency with other browsers, use rem instead!
I'm using CSS transform translateX to move a Gif from left to right. The gif stops and belches towards the end of the Gif animation but the Gif is still being translated along the X co-ordinate, so it doesn't look good!
How can I add a pause/delay at the end of the translateX.
There's a similar question on Stackoverflow regarding a Rotate, and the answer is the following code:
66%, 100% {
transform:rotatey(0deg);
}
But for the life of me I can't figure out how to apply to mine.
.gif-image {
width: 30%;
animation-name: slideLeftToRight;
animation-duration: 20s;
animation-iteration-count: infinite;
}
#keyframes slideLeftToRight {
from {transform: translateX(0px)}
to {transform: translateX(400px)}
}
body{
background-color: #6dba94;
}
<div class="container">
<img class="gif-image" src="https://cdn.dribbble.com/users/672882/screenshots/1972683/character-rig-800x600.gif" />
</div>
This is an interesting one since you can't use a transition delay quite the same as in most circumstances since the GIF never stops. So your case basically boils down to timing up the animation to match with the GIF timing. This is going to be hard to do, especially if you didn't make the GIF yourself. (If you did, maybe it'd be easier for you to tell exactly when the guy starts and stops walking, in milliseconds.)
That said, hard does not mean impossible.
Important note before we start: The GIF is gonna keep playing over and over, even if you update your code in JS Fiddle or CodePen or a Stack Snippet or what have you. So you can end up thinking your animation timing is all off when it's actually not. In testing this, I copied the URL I was working from in CodePen and then kept closing the tab, reopening a new one, and pasting the URL into there to reload it with the GIF starting from its beginning. This is tedious, but I don't know a better way.
Anyway...
First you gotta figure out how long the GIF lasts because it'll make our life a million times easier to base the animation duration around the GIF's duration. I was guessing initially that it'd be a nice round number like exactly 5 seconds, but in testing it seemed to get off after a few iterations, like it was actually slightly longer. I'm ballparking it at 5.15 seconds.
So let's make our guy walk to the right when he's done belching. First we gotta figure out how long exactly he takes before he starts walking. (If you know this number exactly, your life will be way easier. I had to use guess and check.)
With some testing, I figured out he starts walking approximately 42% of the way into the GIF, or about 2163ms into it, if the GIF is 5.15 seconds long (5150ms). So we don't start our translation until that point:
#keyframes animationName {
0% {
transform: translateX(0px);
}
42% {
transform: translateX(0px);
}
100% {
transform: translateX(200px);
}
}
That basically gives us this:
.gif-image {
width: 250px;
animation-iteration-count: infinite;
animation-name: slideLeftToRightRepeating;
animation-duration: 5.15s;
}
#keyframes slideLeftToRightRepeating {
0% {
transform: translateX(0px);
}
42% {
transform: translateX(0px);
}
100% {
transform: translateX(200px);
}
}
body {
background-color: #6dba94;
}
<div class="container">
<div><img class="gif-image" src="https://cdn.dribbble.com/users/672882/screenshots/1972683/character-rig-800x600.gif" /></div>
</div>
Once we get that part down, if you want him to keep walking sideways like you have in your question with a long animation duration, it's just a matter of multiplying our animation duration by however many times you want to repeat the motion, and then dividing our percentages by that same amount.
So let's say you want to have him repeat the animation five times. Our animation duration now becomes (5 * 5.15s) = 20.75s.
Then, in our percentages, every 20% of the animation (because we're dividing it in fifths) will be a repeat of the pattern we established above. So at the 20% mark, we have the same effect as at the 100% mark above.
We figured out he starts walking around 42% of the way through, so we take 42% of 20% to get 8.4%. Our keyframes now look like this:
#keyframes animationName {
0% {
transform: translateX(0px);
}
8.4% {
transform: translateX(0px);
}
20% {
transform: translateX(200px);
}
28.4% {
transform: translateX(200px);
}
40% {
transform: translateX(400px);
}
.....
}
In practice, this proved to be not quite right (I guess my 42% estimation isn't perfect). Revising our numbers a bit, I came up with 0%, 11.5%, 20%, 31.5%, etc.
At the end, we have 100% { transform: translateX(1000px); }. That's a 200px translation five times.
Here's a pretty good starting spot where things go decently well, but the timing isn't exact. I'll leave it up to you to mess with it to get the numbers exactly right and also to adjust the distance he walks each time to fit your circumstance. Hopefully this helps.
Note that I think your life will be easier if you set the width of the GIF as well as the translation distance in fixed units, otherwise you may find that with relative units like percentages that your guy appears to either be walking in place or taking huge bounds across the screen depending how wide it is.
.gif-image {
width: 250px;
animation-iteration-count: infinite;
animation-duration: 20.75s;
animation-name: slideLeftToRightSlowly;
}
#keyframes slideLeftToRightRepeating {
0% {
transform: translateX(0x);
}
42% {
transform: translateX(0px);
}
100% {
transform: translateX(200px);
}
}
#keyframes slideLeftToRightSlowly {
0% {
transform: translateX(0px);
}
11.5% {
transform: translateX(0px);
}
20% {
transform: translateX(200px);
}
31.5% {
transform: translateX(200px);
}
40% {
transform: translateX(400px);
}
51.5% {
transform: translateX(400px);
}
60% {
transform: translateX(600px);
}
71.5% {
transform: translateX(600px);
}
80% {
transform: translateX(800px);
}
91.5% {
transform: translateX(800px);
}
100% {
transform: translateX(1000px);
}
}
body {
background-color: #6dba94;
}
<div class="container">
<div><img class="gif-image" src="https://cdn.dribbble.com/users/672882/screenshots/1972683/character-rig-800x600.gif" /></div>
</div>
I'm writing a custom animation for a project I'm working on. The idea is that the animation is meant to resemble an exclamation mark becoming unhinged from the baseline, swinging for a moment, and then falling off the baseline entirely.
For some reason, only Safari (OSX and iOS) refuses to render the first animation keyframe as a clockwise rotation in a CSS animation I've made. Instead, it renders the keyframe as a counter-clockwise animation, but then works just fine for the following animation keyframes.
Working CodePen example: http://codepen.io/michaelmarcialis/pen/obPYPO
#keyframes unhinged {
0% {
transform: rotate(0deg);
}
15% {
transform: rotate(240deg);
}
30% {
transform: rotate(125deg);
}
45% {
transform: rotate(220deg);
}
60% {
transform: rotate(145deg);
}
75% {
opacity: 1;
transform: rotate(200deg);
}
90% {
opacity: 0;
transform: translate(-0.5rem, 8.57142857142857rem) rotate(215deg);
}
95% {
opacity: 0;
transform: translate(0) rotate(0deg);
}
100% {
opacity: 1;
transform: rotate(0deg);
}
}
All other browsers render the animation as intended, with the first animation keyframe rotating clockwise. Safari is the only one that applies a counter-clockwise rotation in the initial keyframe. I'm assuming Safari is doing this because the distance to travel the rotation is shorter when going counter-clockwise, but it's not honoring the CSS spec properly if that's the case.
Does anyone know a remedy for this?
The problem is that if you try to animate a rotate in safari greater than 180 degrees, it will instead rotate the other way. So if you try to rotate +270 degrees, Safari will animate a rotation of -90 degrees.
The workaround for Safari is to never rotate more than 179 in either direction, then complete the rest of the rotation in another segment.
I am attempting to make a type of CSS only slide transition from one content section to another. In order to do so in an interesting way, I use CSS's perspective and rotateX to in essence lay down the page content. I then am trying to slide the content out towards the bottom of the screen using translateY
Separately, both the translateY and the rotateX work perfectly, no matter what the perspective is. However, when combined, it only works with certain perspectives based on the window size and rotateY value
In this jsFiddle it works as I would like it to in the window sizes I have tried. The problem is that I would like the perspective value to be lower, around 250px, but I cannot do so without breaking the animation.
I tried using a higher rotateY degree instead of making the perspective lower but the same issue occurs
#keyframes slide {
0% { transform: perspective(450px); }
25% { transform: perspective(450px) rotateX(30deg); }
50%,100% { transform: perspective(450px) rotateX(30deg) translateY(100%); }
}
I have tested this on CSS Deck and jsFiddle both in FireFox and Chrome and it seems to be a consistent issue
Can anyone provide me with a reason why this is happening and offer a work around?
Try setting the perspective as a separate rule on a parent element (as opposed to being part of the transform in the animation).
.parent {
perspective: 250px;
}
#keyframes slide {
25% { transform: rotateX(30deg); }
50%, 100% { transform: rotateX(30deg) translateY(100%); }
}
Updated fiddle: http://jsfiddle.net/myajouri/DYpnU/
My reasoning:
The perspective does not change during the animation so there's no point in having it as part of the animation.
Since your elements occupy 100% of the parent's area, setting the perspective on the parent should produce the same result as setting it on the elements themselves (inside transform).
It seems to solve your problem (see fiddle above).
UPDATE: after more experimentation, I found that explicitly setting the translateY(0) initial value in the animation would solve the issue as well.
#keyframes slide {
0% { transform: perspective(150px); }
25% { transform: perspective(150px) rotateX(30deg) translateY(0); }
50%, 100% { transform: perspective(150px) rotateX(30deg) translateY(100%); }
}
Updated fiddle: http://jsfiddle.net/myajouri/YJS3v/
Only a slight improvement over myajouri answer.
At leats in Chrome, you can write
#-webkit-keyframes slide {
0% { -webkit-transform: perspective(50vh); }
10%,15% { -webkit-transform: perspective(50vh) rotateX(30deg) translateY(0%); }
50%,100% { -webkit-transform: perspective(50vh) rotateX(30deg) translateY(100%); }
}
Setting the perspective to the viewport height should make it more responsive that your current setting
demo
(Untested in other browsers)
The platform were I work does not support #keyframes because of security reasons with the #.
My question is if I can replace it with some other css trick.
For example I have this code:
.cubo {
animation:giro 25s infinite linear;
}
#keyframes giro {
0% {transform: rotateX(0deg) rotateY(0deg);}
100% {transform: rotateX(1080deg) rotateY(360deg);
}
}
Can I replace it with transitions or transforms to avoid using the #? (no javascript supported either).
You could instead make it a transition by multiplying the transition duration, rotateX, and rotateY values all by a common factor x and applying the transition class on page load. In my example I multiplied them by 40, but you can go as high as you want but I wouldn't go too high because the processor might overload at some point and break the page. This runs for 1000 seconds, not many people will stay on a page past that
Here is a live demo of that approach
/* CSS */
.cubo {
/* ...Your other code... */
transition: all 1000s linear;
}
.animate {
-webkit-transform: rotateX(43200deg) rotateY(14400deg);
-moz-transform: rotateX(43200deg) rotateY(14400deg);
-o-transform: rotateX(43200deg) rotateY(14400deg);
-ms-transform: rotateX(43200deg) rotateY(14400deg);
transform: rotateX(43200deg) rotateY(14400deg);
}
/* Javascript (ran on page load) */
document.getElementsByClassName('cubo')[0].classList.add('animate');