I have a box that's currently translated, but when I apply a shake animation to it, it jumps to the upper left side of the screen.
I'd like to shake it from it's current position. How might I do this?
Here's my jsfiddle. Please view in a webkit browser (chrome/safari)
http://jsfiddle.net/foreyez/atv7R/
CSS:
div {
background:red;
width:100px;
height:100px;
-webkit-transform: translate3d(50px, 50px, 0px);
}
#-webkit-keyframes shake {
0% { -webkit-transform: translateX(3px); }
50% { -webkit-transform: translateX(-3px); }
100% { -webkit-transform: translateX(0); }
}
.shake {
-webkit-animation-name: shake;
-webkit-animation-duration: 150ms;
-webkit-animation-iteration-count: 20;
-webkit-animation-timing-function: linear;
}
HTML:
<div></div>
JAVASCRIPT:
$('div').addClass('shake')
I ended up using move.js
http://visionmedia.github.io/move.js/
they do what I want with the .then() command. One of these days I'm gonna look at the code to see how they do it because it's all done with translates.
You could animate the position with jQuery and then add the add the class with the keyframe animation to get the desired effect.
http://jsfiddle.net/atv7R/3/
$('div').animate({
top: 50,
left: 50
}, 1000).addClass('shake');
or you could acomplish the same thing with css:
http://jsfiddle.net/atv7R/5/
div {
position:absolute;
top: 10px;
left:10px;
background:red;
width:100px;
height:100px;
}
#-webkit-keyframes shake {
0% {
-webkit-transform: translate3d(0px, 0px, 0px);
}
50% {
-webkit-transform: translate3d(3px, 3px, 0px);
}
100% {
-webkit-transform: translate3d(0px, 0px, 0px);
}
}
.shake {
top: 50px;
left: 50px;
-webkit-transition: top 1s, left 1s;
-webkit-animation-name: shake;
-webkit-animation-delay: 1s;
-webkit-animation-duration: 150ms;
-webkit-animation-iteration-count: 20;
-webkit-animation-timing-function: linear;
}
Related
I have the following code for an image of a plane to come in from the left hand side of the page, land... ride on straight for 800px then take off again off the opposite side of the page.
But what is getting to me is the jerkiness between each percentage.
is there a away for it to smooth out the transitions between keyframes.
#keyframes plane-right {
0% {
visibility:visible;
transform: translate(-2000px, -400px) rotate(-20deg) scaleX(-1);
}
40% {
visibility:visible;
transform: translate(-400px, -0px) rotate(-0deg) scaleX(-1);
}
60% {
visibility:visible;
transform: translate(400px, -0px) rotate(-5deg) scaleX(-1);
}
100% {
visibility:visible;
transform: translate(2000px, -400px) rotate(-40deg) scaleX(-1);
}
}
Add animation duration and animation timing-function to control the length of the animation and the timing (smoothness).
.plane-right-div {
width: 100px;
height: 70px;
background-color: #bada55;
border-radius: 5px;
animation-name: plane-right;
animation-duration: 6s;
animation-timing-function: ease;
}
#keyframes plane-right {
0% {
visibility: visible;
transform: translate(-2000px, -400px) rotate(-20deg) scaleX(-1);
}
40% {
visibility: visible;
transform: translate(-400px, -0px) rotate(-0deg) scaleX(-1);
}
60% {
visibility: visible;
transform: translate(400px, -0px) rotate(-5deg) scaleX(-1);
}
100% {
visibility: visible;
transform: translate(2000px, -400px) rotate(-40deg) scaleX(-1);
}
}
<div class="plane-right-div"></div>
Add following animation-timing property to your image tag, this will help
transform-origin:50px 5px;
transition:transform 1s ease-in-out 0s;
animation-duration: 2.2s;
animation-name: paragato;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: ease-in-out;
-webkit-animation-timing-function: ease-in-out;
I am trying to create an animation of a balloon flying. All is weel in all modern browsers except IE11.
I am using translateX and translateY without any problem but scale is causing the image to become blurry.
#media (min-width: 1100px) {
.balloon-outer,
.balloon-inner,
.balloon {
height: 100%;
position: absolute;
width: 100%;
bottom: 0;
right: 0;
animation-duration: 60s;
animation-delay: 0;
animation-iteration-count: infinite;
animation-direction: normal;
will-change: transform;
pointer-events: none;
}
.balloon-outer {overflow-y: hidden;
transform-origin: 50% 50%;
animation-name: travel-x;
animation-timing-function: ease-in;
transform: translateX(-20%);
}
.balloon {
transform-origin: 50% 50%;
animation-name: travel-y;
animation-timing-function: ease-out;
transform: translateY(90%);
}
.balloon-inner {background:url("https://www.inty.com/wp-content/uploads/balloon.png") no-repeat scroll 100% 100% / auto 40%;
transform-origin: 100% 100%;
animation-name: scale;
animation-timing-function: linear;
transform: scale(3);
}
}
#keyframes scale {
0% {transform: scale(3);}
80% {transform: scale(0);}
100% {transform: scale(0);}
}
#keyframes travel-x {
0% {transform: translateX(-10%);}
80% {transform:translateX(-45%);}
100% {transform:translateX(-45%);}
}
#keyframes travel-y {
0% {transform: translateY(120%);}
80% {transform:translateY(-70%);}
100% {transform:translateY(-70%);}
}
<div class="balloon-outer"><div class="balloon"><div class="balloon-inner"></div></div></div>
http://codepen.io/rachelreveley/pen/xdLGEO
I have tried this trick which I have seen in several places but it made no difference.
-webkit-backface-visibility: hidden;
-ms-transform: translateZ(0); /* IE 9 */
-webkit-transform: translateZ(0); /* Chrome, Safari, Opera */
transform: translateZ(0);
Try changing all your translateX and translateY to translate3d like:
#keyframes travel-x {
0% {transform: translate3d(-10%,0,0);}
80% {transform:translate3d(-45%,0,0);}
100% {transform:translate3d(-45%,0,0);}
}
#keyframes travel-y {
0% {transform: translate3d(0,120%,0);}
80% {transform:translate3d(0,-70%,0);}
100% {transform:translate3d(0,-70%,0);}
}
do the same everywhere you have been using translates in your example. translate3d enables hardware acceleration which will help with animations.
you can see this post for more info.
You can use a fallback to IE-11 with the vendor prefix "-ms-transform".
for example:
.balloon-outer {overflow-y: hidden;
transform-origin: 50% 50%;
animation-name: travel-x;
animation-timing-function: ease-in;
transform: translateX(-20%);
-ms-transform: translateX(-20%);
}
See the answer here.
CSS3 transform:scale in IE
I'm using the keyframes to create an infinite scale up and scale down of a div on mouseover.
As you can see from the link below the parent box increase its sizes and then the child div start to scale up and down.
I would like that on mouse out, before the parent div will scale down, the child div return to its regular sizes in a smooth way.
Now, as you can see, it return to the original sizes suddenly, without any smoothness.
My keyframes:
#keyframes imageZoom {
0% { transform: scale(1); }
50% { transform: scale(1.24); }
100% { transform: scale(1);}
}
#-moz-keyframes imageZoom {
0% { -moz-transform: scale(1);}
50% { -moz-transform: scale(1.24); }
100% { -moz-transform: scale(1); }
}
#-webkit-keyframes imageZoom {
0% { -webkit-transform: scale(1); }
50% {-webkit-transform: scale(1.24); }
100% { -webkit-transform: scale(1); }
}
#-ms-keyframes imageZoom {
0% { -ms-transform: scale(1); }
50% { -ms-transform: scale(1.24); }
100% { -ms-transform: scale(1); }
}
The child div styles:
#myFeaturedItems:hover article {
animation: imageZoom linear 50s;
animation-iteration-count: infinite;
-webkit-animation: imageZoom linear 50s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-delay: 1.5s;
animation-delay: 1.5s;
}
#myFeaturedItems article {
background-image: url('https://images.unsplash.com/photo-1447688812233-3dbfff862778?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=01b98cd0603404826ec5df6d9ef46dfc');
background-position: center center;
background-size: cover;
display: block;
height: 100%;
width: 100%;
}
My demo link: http://emanuelezenoni.com/dev/test/
Thanks a lot!
You don't need an animation to achieve what you want. A transition when you hover over the article is suitable. See my very basic example of the transition here below.
What it does:
transition: transform 1s ease-in-out;
This will put a transition on the property transform for 1s with easing ease-in-out. When you hover over .box, the transform: scale(1.25); will run, because we said that a transition was applied on it. The overflow: hidden; makes sure that the content will not be bigger than the box it's in.
You can tweak with the settings to your needs.
body,
html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
width: 100%;
height: 100%;
min-height: 100%;
overflow: hidden;
}
.box {
margin-left: 50%;
width: 50%;
min-height: 100%;
background-image: url('http://i.imgur.com/AzeiaRY.jpg');
background-size: cover;
background-position: center center;
-webkit-transition: -webkit-transform 1s ease-in-out;
transition: transform 1s ease-in-out;
}
.box:hover {
-webkit-transform: scale(1.25);
transform: scale(1.25);
}
<div class="container">
<article class="box">
</article>
</div>
I just built a small animation and it does exactly as I want it to, except a small problem, I have bounceIn animation on 2 HTML elements, my HTML is below:
<div class="test animated bounceInDown">
<span class="animated bounceInDown delay">I am animation</span>
</div>
My CSS:
.test {
height: 200px;
width: 200px;
background-color:yellow;
display: table;
}
.test span {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.animated {
-webkit-animation-duration: 2s;
-o-animation-duration: 2s;
animation-duration: 2s;
}
.delay {
-webkit-animation-delay: 1s;
-o-animation-delay: 1s;
animation-delay: 1s;
}
#-webkit-keyframes bounceInDown {
0%, 60%, 75%, 90%, 100% {
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
transform: translate3d(0, -3000px, 0);
}
60% {
opacity: 1;
transform: translate3d(0, 25px, 0);
}
75% {
transform: translate3d(0, -10px, 0);
}
90% {
transform: translate3d(0, 5px, 0);
}
100% {
transform: none;
}
}
.bounceInDown {
-webkit-animation-name: bounceInDown;
animation-name: bounceInDown;
}
Now of course span is a child of the div, on the span I have a animation-delay, problem is, the animation on the span has a small bug: it follows the animation of the div and then executes its own animation, I.E. on page load, the span element still bounces in with the div even though I have an animation delay.
I am more interested in WHY this is happening than HOW to solve my problem. Here's a fiddle to see what I am talking about: Fiddle
Nothing is wrong about your animation. Just that the configuration of your animation is not good.
The problem appear because before the animation trigger. The text will be render within the animating parent.
When your text got triggered by animation it will animation on it own. Which mean it will be move up with 3000px.
=> should concern about animation a child in within an animating parent.
When you apply animation to an element, all child elements too undergo the animation. So, in your case, span tag too animates with the parent.
After time in animation-delay's value passes after page load, the animation on child span takes place.
This isn't a bug. Its the way animations work on child elements.
To fix the problem: Just simply use opacity with your animation and animation-fill-mode and it will do the trick
http://jsfiddle.net/ev5ur00n/2/
.test {
height: 200px;
width: 200px;
background-color:yellow;
display: table;
}
.test span {
display: table-cell;
vertical-align: middle;
text-align: center;
opacity: 0;
}
.animated {
-webkit-animation-duration: 2s;
-o-animation-duration: 2s;
animation-duration: 2s;
}
.delay {
-webkit-animation-delay: 1s;
-o-animation-delay: 1s;
animation-delay: 1s;
}
#-webkit-keyframes bounceInDown {
0%, 60%, 75%, 90%, 100% {
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
transform: translate3d(0, -3000px, 0);
}
60% {
opacity: 1;
transform: translate3d(0, 25px, 0);
}
75% {
transform: translate3d(0, -10px, 0);
}
90% {
transform: translate3d(0, 5px, 0);
}
100% {
transform: none;
opacity: 1;
}
}
.bounceInDown {
-webkit-animation-name: bounceInDown;
animation-name: bounceInDown;
}
.bounceInDown2 {
-webkit-animation-name: bounceInDown;
animation-name: bounceInDown;
-webkit-animation-fill-mode: forwards; /* Chrome, Safari, Opera */
animation-fill-mode: forwards;
}
<div class="test animated bounceInDown">
<span class="animated bounceInDown2 delay">I am animation</span>
</div>
I'm trying to chain CSS3 animations together, but they behave very weird sometimes. For example, in this pen, why won't the last animation start? I got it working before, but it doesn't anymore, and I used the same setup. The code I'm pasting here is a little bit simplified, but the animations are exactly the same:
HTML:
<div class="box"></div>
CSS:
body {
padding: 60px;
}
.box {
width: 100px;
height: 100px;
background-color: black;
animation-name: fadeIn, fall, elastic;
animation-timing-function: ease, ease-in, ease-out;
animation-duration: 1s, 0.5s, 0.5s;
animation-delay: 0s, 0s, 0.5s;
animation-fill-mode: forwards, forwards, forwards;
}
#keyframes fadeIn {
0% { opacity: 0; }
100% { opacity: 1; }
}
#keyframes fall {
0% { transform: translateY(-100px); }
100% { transform: translateY(0px); }
}
#keyframes elastic {
0% { transform: translateY(0px); }
20% { transform: translateY(60px); }
40% { transform: translateY(-20px); }
60% { transform: translateY(10px); }
80% { transform: translateY(-5px); }
100% { transform: translateY(0px); }
}
Maybe I'm wrong... but it seems that this does not "chain" them since they play simultaneously. If that's the case, then the last one probably isn't working because you're already keyframeing translateY in the second animation.