I want to create an animation with falling objects, with different start time and different falling speed. The objects stop falling when they reach the position in the image (see below).
What's the best way to actually animate this? Should I use Adobe animator/After effects or is CSS enough?
I'm open for suggestions.
The black lines are going down even when the object stop (please ignore the shadows beneath the object)
Try something like this
img {
transition: all 5s;
top: 0;
position: absolute;
}
img#abc {
left: 50px;
}
img#def {
left: 120px;
}
img#ghi {
left: 180px;
}
img.abc {
transition: all 5s 1.5s;
top: 150px;
}
img.def {
transition: all 3s 0.5s;
top: 175px;
}
img.ghi {
transition: all 4s 1s;
top: 165px;
}
<script>
function myFunction() {
var element = document.getElementById("abc");
element.classList.add("abc");
var element = document.getElementById("def");
element.classList.add("def");
var element = document.getElementById("ghi");
element.classList.add("ghi");
}
</script>
<button onclick="myFunction()">Try it</button>
<img src="https://i.stack.imgur.com/NDtpp.png" id="abc" height="50" width="50"/>
<img src="https://i.stack.imgur.com/NDtpp.png" id="def" height="50" width="50"/>
<img src="https://i.stack.imgur.com/NDtpp.png" id="ghi" height="50" width="50"/>
Code for background-animation
#keyframes animatedBackground {
from { background-position: 0 100%; }
to { background-position: 0 0; }
}
#-webkit-keyframes animatedBackground {
from { background-position: 0 100%;; }
to { background-position: 0 0; }
}
#-ms-keyframes animatedBackground {
from { background-position:0 100%;; }
to { background-position: 0 0; }
}
#-moz-keyframes animatedBackground {
from { background-position: 0 100%;; }
to { background-position: 0 0; }
}
#animate-area {
width: 100%;
height: 400px;
background-image: url(https://image.ibb.co/kuXpay/static.png);
background-position: 0 100%;
background-repeat: repeat-y;
animation: animatedBackground 20s linear infinite;
-ms-animation: animatedBackground 20s linear infinite;
-moz-animation: animatedBackground 20s linear infinite;
-webkit-animation: animatedBackground 20s linear infinite;
}
<div id="animate-area">
</div>
Related
I have created sample
CodePen here.
I tried below but didn't work.
.elementToFadeInAndOut {
width:200px;
height: 200px;
background: red;
-webkit-animation: fadeinout 4s linear forwards;
animation: fadeinout 4s linear forwards;
}
#-webkit-keyframes fadeinout {
0%,100% { opacity: 0; }
50% { opacity: 1; }
}
#keyframes fadeinout {
0%,100% { opacity: 0; }
50% { opacity: 1; }
}
As you will see this sample has 3 images. I give them id = "imge1", "imge2", "imge3"
img3 keeps rotating using keyframe.
I need to show img1 and img2 showing kinda fadein-fadeout effect.
so when img3 rotates to bottom that time may be fadeout img1 and fadeIn img2. (or other way around is fine)
basically 2 images should keep replacing with some fade effect and img3 keeps rotating.
Here is a link I tried but could not achieve solution.
CSS animation, fade in fade out opacity on automated slideshow
CSS how to make an element fade in and then fade out?
also, this needs to be done using pure-css only. I have to put this in nextjs project.
Thanks
You need animation-delay and animation-iteration-count to achieve that
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}
figure{
width: 100vw;
height: 50vh;
position: relative;
background: green;
text-align: center;
}
picture{
position: relative;
display: inline-block;
width: 25%;
}
picture img{
width: 100%
}
picture:not(:last-of-type){opacity: 0}
picture:first-of-type{
background: red;
animation: fadeinout 4s linear forwards infinite;
}
picture:nth-child(2){
background: red;
animation: fadeinout 4s 2s linear forwards infinite;/*you need to add the delay here*/
}
picture:last-of-type{
animation: spin 4s linear infinite;
}
figcaption{
position: absolute;
bottom: 0;
left:0;
width: 100%;
}
#keyframes fadeinout {
50% { opacity: 1; }
}
#keyframes spin {
to { transform: rotate(360deg);}
}
<figure>
<picture>img1</picture>
<picture>img2</picture>
<picture>
<img class="img3" src="https://anima-uploads.s3.amazonaws.com/projects/5e81f9028ef92977fa0913c0/releases/5e81f928d7217864bf001225/img/login-radar-1.png" alt="img" />
</picture>
<figcaption>Css Labs</figcaption>
</figure>
See below. I added a background color to the third image to make it visible.
#img3 {
background-color: red; /* to make it visible */
}
.flexDisplay {
display: flex;
}
.wrapper {
display: flex;
justify-content: space-evenly;
}
.loginImage {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
#keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.img1 {
animation: spin 3s linear infinite;
opacity: 0.1;
width: 200px;
height: 200px;
align-items: center;
}
.elementToFadeInAndOut {
width: 200px;
height: 200px;
background: red;
animation: fadeinout 4s linear infinite;
}
#keyframes fadeinout {
0%,
100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
<div class="flexDisplay">
<div class="wrapper">
<img id="img1" class="elementToFadeInAndOut" src="https://anima-uploads.s3.amazonaws.com/projects/5e81f9028ef92977fa0913c0/releases/5e81fc3f75aec5860f52b6a0/img/loginsuper-rectangle-copy.png " class="loginImage" alt="branding logo" />
<img id="img2" class="elementToFadeInAndOut" src="https://anima-uploads.s3.amazonaws.com/projects/5e81f9028ef92977fa0913c0/releases/5e81fc3f75aec5860f52b6a0/img/loginsuper-rectangle.png" class="loginImage elementToFadeInAndOut" alt="branding logo" />
<img id="img3" class="img1" src="https://anima-uploads.s3.amazonaws.com/projects/5e81f9028ef92977fa0913c0/releases/5e81f928d7217864bf001225/img/login-radar-1.png" alt="img" />
</div>
</div>
Basically, you need to apply 2 different animation functions to the different elements.
I have used z-index to let the images overlap each other and
set the infinite property for the duration of your animation.
You can set an interval for your images using animation-delay.
.flexDisplay{
display: flex;
background: #f1f1f1;
}
.wrapper{
display: flex
}
.img1{
z-index:3;
}
.loginImage1{
width: 100%;
height: 100%;
position:absolute;
left:0;
top:0;
z-index:1;
}
.loginImage2{
width: 100%;
height: 100%;
position:absolute;
left:0;
top:0;
z-index:2;
}
#keyframes spin {
from {
transform:rotate(0deg);
}
to {
transform:rotate(360deg);
}
}
.img1{
animation: spin 3s linear infinite;
width: 200px;
height: 200px;
align-items: center;
}
.img2{
position: relative;
width: 200px;
height: 200px;
}
.elementToFadeInAndOut1 {
width:200px;
height: 200px;
background: red;
-webkit-animation: fadeinout 4s linear infinite;
animation: fadeinout 4s linear infinite;
}
#-webkit-keyframes fadeinout {
0%,100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
#keyframes fadeinout {
0%,100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
.elementToFadeInAndOut2 {
width:200px;
height: 200px;
background: red;
-webkit-animation: fadeinout 4s linear infinite;
animation: fadeinout 4s linear infinite;
animation-delay:5s;
}
#-webkit-keyframes fadeinout1 {
0%,100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
#keyframes fadeinout1 {
0%,100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
Created this pen: https://codepen.io/spaceCadett/pen/wvKKowL
I have created a div with a background image. Using keyframe animation I want it to move vertically up continuously, which it does however at the end of the frame it jumps then continues. I am new with keyframes. I can not use JS.
I have tried looking at the questions on here but they are mainly focused on sliders.
This is my code so far:
<style>
#animate-area {
background-image: url(/image.png);
width: 100%;
height: 500px;
background-position: 0px 0px;
background-repeat: repeat-x;
-webkit-animation: animatedBackground 5s ease-in-out infinite;
-moz-animation: animatedBackground 5s ease-in-out infinite;
animation: animatedBackground 5s ease-in-out infinite;
}
#-webkit-keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 0 100%; }
}
#-moz-keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 0 100%; }
}
#keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 0 100%; }
}
</style>
<div id="animate-area"></div>
As soon as the frame has finished it jumps and then continues. Is it possible to for it to continuously loop without jumping with a background image? If so, how?
Live example to continuously move up :
#animate-area {
background-image: url('https://pt.freelogodesign.org/Content/img/logo-ex-2.png');
width: 100%;
height: 500px;
background-position: 0;
animation: slideup 5s linear 1s infinite;
position:absolute;
}
#keyframes slideup {
0% { background-position: 0 0; }
50% { background-position: 0 -500px; }
100% { background-position: 0 -900px; }
}
<div id="animate-area"></div>
you can use twice the same image with opposite coordonates to move from/to :
#animate-area {
background-image: url(http://dummyimage.com/100&text=img_1), url(http://dummyimage.com/100&text=img_2);
width: 100%;
height: 500px;
background-position: 0px 0px, 0 -100%;
background-repeat: repeat-x;
animation: animatedBackground 5s ease-in-out infinite;
}
#keyframes animatedBackground {
from {
background-position: 0 0, 0 -100%;
}
to {
background-position: 0 100%, 0 0;
}
}
<div id="animate-area"></div>
different text is used to show what happens
currently I'm using this code:
#div { background-image: url('imageurl.com'), url('imageurl2.com'); position: absolute !important; right: 0; left: 0; height: 210px !important; display: table-cell !important; vertical-align: middle !important;}
#keyframes FadeInOut {
0% {
opacity:1;
}
45% {
opacity:1;
}
55% {
opacity:0;
}
100% {
opacity:0;
}
}
#div img.top {
animation-name: FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 10s;
animation-direction: alternate;
}
I'm actually trying to implement the code from Demo 3 on this website:
http://css3.bradshawenterprises.com/cfimg/
In that demo, there are two images in one div and the code is just fading the first one in and out on a timer. I tried implementing this myself using the above code, but it's fading anything in and out. Does anyone know what I'm missing?
If you need implementation through background-image you can use pseudo-element:
#cf2 {
position:relative;
height:281px;
width:450px;
margin:0 auto;
background-image: url("http://css3.bradshawenterprises.com/images/Windows%20Logo.jpg");
}
#cf2::after{
content: ' ';
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
background-image: url("http://css3.bradshawenterprises.com/images/Turtle.jpg");
background-repeat: no-repeat;
background-position: 50% 0;
background-size: cover;
}
#keyframes cf3FadeInOut {
0% {
opacity:1;
}
45% {
opacity:1;
}
55% {
opacity:0;
}
100% {
opacity:0;
}
}
#cf2::after {
animation-name: cf3FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 10s;
animation-direction: alternate;
}
<div id="cf2">
</div>
here's the implementation, they use separate <img> tags to show/hide images:
they are absolutely positioned one above the other, that one which is on top is just showing and hiding by the animation (which changes its opacity) - so the bottom one just becomes visible when top one has opacity = 0
#keyframes cf3FadeInOut {
0% {
opacity: 1;
}
45% {
opacity: 1;
}
55% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#cf3 img.top {
animation-name: cf3FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 10s;
animation-direction: alternate;
}
#cf3 img {
position: absolute;
left: 0;
}
#cf3 {
position: relative;
height: 281px;
width: 450px;
margin: 0 auto;
}
<div id="cf3" class="shadow">
<img class="bottom" src="http://css3.bradshawenterprises.com/images/Turtle.jpg">
<img class="top" src="http://css3.bradshawenterprises.com/images/Windows%20Logo.jpg">
</div>
Html5:
<div id="slideshow">
<div id='animate-area'>
</div>
</div>
Css:
body {
margin: 0;
padding: 0;
}
#slideshow {
position: relative;
overflow: hidden;
height: 145px;
}
#animate-area {
height: 100%;
width: 2538px;
position: absolute;
left: 0;
top: 0;
background-image: url('../img/banner.png');
animation: animatedBackground 40s 5s linear infinite;
-ms-animation: animatedBackground 40s linear infinite;
-moz-animation: animatedBackground 40s linear infinite;
-webkit-animation: animatedBackground 30s linear infinite;
}
/* Put your css in here */
#keyframes animatedBackground {
from { left: 0; }
to { left: -1269px; }
}
#-webkit-keyframes animatedBackground {
from { left: 0; }
to { left: -1269px; }
}
#-moz-keyframes animatedBackground {
from { left: 0; }
to { left: -1269px; }
}
JSfiddle:
jsfiddle.net/cz04c4nx/1
Using this image, I need show like, http://jsfiddle.net/5pVr4/6/. I tried, but for my particular image url('../img/banner.png') when run in localhost, can't able to get.
I think i solved your problem. You can use this code and it may be help you.I edited that code which you can make similar animate background image.
CSS Code:
#-webkit-keyframes MOVE-BG {
from {
-webkit-transform: translateX(0);
}
to {
-webkit-transform: translateX(-550px);
}
}
#content {
height: 100px;
text-align: center;
font-size: 26px;
color: white;
position: relative;
overflow: hidden;
}
.bg{
position: absolute;
left: 0;
right: -550px;
top: 0;
bottom: 0;
background: url(http://s30.postimg.org/qnju89rkx/banner.png) 0% 0% repeat;
z-index: -1;
-webkit-animation-name: MOVE-BG;
-webkit-animation-duration: 10s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
}
Live Working Demo
i have a question about css steps animation, so i have 12 images, and i want to slide this images like animated gif. But i couldn't achieve that.
My Demo : http://cssdeck.com/labs/full/9hwv565g
what i want to : http://cssdeck.com/labs/css-image-sprite-animations-with-steps-function
body {
text-align: center;
}
#-webkit-keyframes wink {
from { background-position: 0px; }
to { background-position: -500px; }
}
#-moz-keyframes wink {
from { background-position: 0px; }
to { background-position: -500px; }
}
#keyframes wink {
from { background-position: 0px; }
to { background-position: -500px; }
}
.hi {
width: 120px;
height: 120px;
background-image: url("http://i44.tinypic.com/nq7mrp.png");
margin: 0 auto;
-webkit-animation: wink .8s steps(10, end) infinite;
-moz-animation: wink .8s steps(10, end) infinite;
animation: wink .8s steps(10, end) infinite;
}
Can you help me?
Thanks in advance
You need to adjust the background-position value and the steps argument, in you case your image measures 1595px in width and has 12 frames:
body {
text-align: center;
}
#-webkit-keyframes wink {
from { background-position: 0px; }
to { background-position: -1595px; }
}
#-moz-keyframes wink {
from { background-position: 0px; }
to { background-position: -1595px; }
}
#keyframes wink {
from { background-position: 0px; }
to { background-position: -1595px; }
}
.hi {
width: 133px;
height: 126px;
background-image: url("http://i44.tinypic.com/nq7mrp.png");
margin: 0 auto;
-webkit-animation: wink .8s steps(12, end) infinite;
-moz-animation: wink .8s steps(12, end) infinite;
animation: wink .8s steps(12, end) infinite;
}
Demo here