How to make distance for moving image in html5 - html

This is what I tried:
css code:
body {
margin: 0;
padding: 0;
}
#slideshow {
position: relative;
overflow: hidden;
height: 100px;
}
#animate-area {
height: 100%;
width: 2538px;
position: absolute;
left: 0;
top: 0;
background-image: url('http://s10.postimg.org/noxw294zd/banner.png');
animation: animatedBackground 40s linear infinite;
-ms-animation: animatedBackground 40s linear infinite;
-moz-animation: animatedBackground 40s linear infinite;
-webkit-animation: animatedBackground 40s 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; }
}
Now what I need, every once rotational completed, then again start to move from right to left. I need some distance for every rotational completed.
Can somebody help to fix this?
Thanks in advance.
http://jsfiddle.net/6d6xa65n/4/

There isn't any delay between iterations in css3 other than animation-delay, which is used at the beginning, however you can use jQuery for delay. For direction from right to left change:
animation: animatedBackground 40s linear infinite alternate;
-ms-animation: animatedBackground 40s linear infinite alternate;
-moz-animation: animatedBackground 40s linear infinite alternate;
-webkit-animation: animatedBackground 40s linear infinite alternate;
If you want to add delay change to:
animation: animatedBackground 40s 5s linear infinite alternate;
-ms-animation: animatedBackground 40s 5s linear infinite alternate;
-moz-animation: animatedBackground 40s 5s linear infinite alternate;
-webkit-animation: animatedBackground 40s 5s linear infinite alternate;
Or add this, which will give you a delay at the end and beginning if you mean delay by "distance":
background-image: url('http://s10.postimg.org/noxw294zd/banner.png');
animation: animatedBackground 5s linear infinite alternate;
-ms-animation: animatedBackground 5s linear infinite alternate;
-moz-animation: animatedBackground 5s linear infinite alternate;
-webkit-animation: animatedBackground 5s linear infinite alternate;
}
/* Put your css in here */
#keyframes animatedBackground {
0% { left: 0; }
25% { left: 0; }
50% {left: -2000px;}
100% { left: -2000px; }
}
#-webkit-keyframes animatedBackground {
0% { left: 0; }
25% { left: 0; }
50% {left: -2000px;}
100% { left: -2000px; }
}
#-moz-keyframes animatedBackground {
0% { left: 0; }
25% { left: 0; }
50% {left: -2000px;}
100% { left: -2000px; }
}

Related

Endless Rotating DIV but with Absolute Positioning

I'm facing a problem, I have a div with an absolute position, and I'm trying to rotate it 360 degrees with an endless looping. But if I use the transform: translate (-50%,-50%) to fully center this div, it won't work properly.
HTML
<div class="randomName"></div>
CSS
.randomName {
background-color: orange;
width: 1500px;
height: 1500px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
animation: orbita 2s linear infinite;
-webkit-animation: orbita 2s linear infinite;
-moz-animation: orbita 2s linear infinite;
-o-animation: orbita 2s linear infinite;
}
#keyframes orbita {
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
Not sure why is not working. Can someone guide me? thanks!
When using the animation you are overriding the initial transform property by specifying a new one. Instead you need to append rotation to translate in order to keep both of them working:
.randomName {
background-color: orange;
width: 150px;
height: 150px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
animation: orbita 2s linear infinite;
-webkit-animation: orbita 2s linear infinite;
-moz-animation: orbita 2s linear infinite;
-o-animation: orbita 2s linear infinite;
}
#keyframes orbita {
0% {
transform:translate(-50%, -50%) rotate(0deg);
}
100% {
transform:translate(-50%, -50%) rotate(360deg);
}
}
<div class="randomName"></div>
Another solution is to center your element using another way and keep the animation as it is.
Here is an example using flex to center the element:
body {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.randomName {
background-color: orange;
width: 150px;
height: 150px;
animation: orbita 2s linear infinite;
-webkit-animation: orbita 2s linear infinite;
-moz-animation: orbita 2s linear infinite;
-o-animation: orbita 2s linear infinite;
}
#keyframes orbita {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
<div class="randomName"></div>

Place a Div(s) with Absolute Position on top of an Image so that it won't move on resize.

Is there a way to force animated elements to stay positioned on top of another image?
PROBLEM:
When you resize the browser all of the Animated Elements slide Horizontally and/or Vertically.
Notice the pink square div [as well as the others] move when I resize the screen, I want it to stay in the same place and NOT MOVE.
I've tried to use absolute position on the div, but that doesn't stop
them from moving around on resize. What can I do to keep the elements in a certain spot on the picture?
Please use my fiddle to demonstrate your solution
HTML:
<center>
<div id="wrapper">
<img class="buildingtotal img-responsive" src="http://www.penguins-world.com/wp-content/uploads/emperor_penguin.jpg" >
<div id="animation">
<div class="bubble toprow"> </div>
<div class="bubble toprow"> </div>
<div class="bubble toprow"> </div>
<div class="bubble toprow"> </div>
<div class="bubble bottomrow"> </div>
<div class="bubble bottomrow"> </div>
<div class="bubble bottomrow"> </div>
<div class="bubble bottomrow"> </div>
</div>
<img class="buildingsolo" src="http://i1207.photobucket.com/albums/bb466/audetwebdesign/jsFiddle%20Demos/Puffins.jpg" >
</div>
</center>
CSS:
.toprow{top:0;}
.bottomrow{top:0; margin-top:15%;}
.bubble {
height: 100px;
width: 100px;
position:absolute;
opacity:0;
}
#animation div:nth-of-type(1) {
-webkit-animation: fadein 6s ease-in-out -8s infinite alternate;
-moz-animation: fadein 6s ease-in-out -8s infinite alternate;
animation:fadein 6s ease-in-out -8s infinite alternate;
}
#animation div:nth-of-type(2) {
-webkit-animation: fadein 6s ease-in-out 8s infinite alternate;
-moz-animation: fadein 6s ease-in-out 8s infinite alternate;
animation: fadein 6s ease-in-out 8s infinite alternate;
}
#animation div:nth-of-type(3) {
-webkit-animation: fadein 6s ease-in-out 16s infinite alternate;
-moz-animation: fadein 6s ease-in-out 16s infinite alternate;
animation: fadein 6s ease-in-out 16s infinite alternate;
}
#animation div:nth-of-type(4) {
-webkit-animation: fadein 6s ease-in-out 24s infinite alternate;
-moz-animation: fadein 6s ease-in-out 24s infinite alternate;
animation:fadein 6s ease-in-out 24s infinite alternate;
}
#animation div:nth-of-type(5) {
-webkit-animation: fadein 6s ease-in-out -16s infinite alternate;
-moz-animation: fadein 6s ease-in-out -16s infinite alternate;
animation: fadein 6s ease-in-out -16s infinite alternate;
}
#animation div:nth-of-type(6) {
-webkit-animation: fadein 6s ease-in-out 40s infinite alternate;
-moz-animation: fadein 6s ease-in-out 40s infinite alternate;
animation: fadein 6s ease-in-out 40s infinite alternate;
}
#animation div:nth-of-type(7) {
-webkit-animation: fadein 6s ease-in-out -24s infinite alternate;
-moz-animation: fadein 6s ease-in-out -24s infinite alternate;
animation:fadein 6s ease-in-out -24s infinite alternate;
}
#animation div:nth-of-type(8) {
-webkit-animation: fadein 6s ease-in-out 32s infinite alternate;
-moz-animation: fadein 6s ease-in-out 32s infinite alternate;
animation: fadein 6s ease-in-out 32s infinite alternate;
}
#-webkit-keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
#-moz-keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
#keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
.toprow{top:25%; }
.bottomrow{top:0%; }
.bubble:nth-child(1)
{
background: #ff0; left:10%;
}
.bubble:nth-child(2)
{
background: #333; left:30%;
}
.bubble:nth-child(3)
{
background: #f90; left:60%;
}
.bubble:nth-child(4)
{
background: #e43; left:80%;
}
.bubble:nth-child(5)
{
background: #e38; left:10%;
}
.bubble:nth-child(6)
{
background: #338;left:30%;
}
.bubble:nth-child(7)
{
background: #fdd; left:60%;
}
.bubble:nth-child(8)
{
background: #53d; left:80%;
}
}
#media(max-width:630px)
{
#animation {display:none!important;}
.buildingsolo {display:none !important;}
.buildingtotal {display:block !important; top:0!important;}
}
Wrap each image in a div with position:relative;
<div style="position:relative;">
<div style="position:absolute;"><!--box goes here--></div>
<img .../>
</div>
You can also try:
#wrapper { position:relative; display:inline-block; margin:0 auto; }
 
EDIT
Make sure the wrapper is the same width as the image, else it will not work:
<div id="wrapper" style="display:inline-block;">

CSS slideshow with fade in/out delay

I made an CSS slideshow with 3 images animated by keyframes that makes a fade in/out effect. So far, so well. But there's a problem with the animation on the second loop of the slideshow.
Im going to explain my best: the first loop animation works perfectly, but once the first image come back again there's a fade to white on all the slides that I like to avoid.
I don't understand why the first loop works perfectly and then the other loops have this fade to white issue. You can see this problem on the Snippet.
Help is really apreciated!
.imgbox{
display: flex;
align-items: center;
height: 100%;
width: 100%;
background-position: center center;
background-size: cover;
}
#img1{
position: absolute;
z-index: 3;
-webkit-animation: slideshow 15s linear 0s infinite;
-moz-animation: slideshow 15s linear 0s infinite;
-ms-animation: slideshow 15s linear 0s infinite;
-o-animation: slideshow 15s linear 0s infinite;
animation: slideshow 15s linear 0s infinite;
}
#img2{
position: absolute;
z-index: 2;
-webkit-animation: slideshow 15s linear 5s infinite;
-moz-animation: slideshow 15s linear 5s infinite;
-ms-animation: slideshow 15s linear 5s infinite;
-o-animation: slideshow 15s linear 5s infinite;
animation: slideshow 15s linear 5s infinite;
}
#img3{
position: absolute;
z-index: 1;
-webkit-animation: slideshow 15s linear 10s infinite;
-moz-animation: slideshow 15s linear 10s infinite;
-ms-animation: slideshow 15s linear 10s infinite;
-o-animation: slideshow 15s linear 10s infinite;
animation: slideshow 15s linear 10s infinite;
}
#-webkit-keyframes slideshow {
25% { opacity: 1;}
30% { opacity: 0;}
95% { opacity: 0;}
100% { opacity: 1;}
}
#-moz-keyframes slideshow {
25% { opacity: 1;}
30% { opacity: 0;}
95% { opacity: 0;}
100% { opacity: 1;}
}
#-ms-keyframes slideshow {
25% { opacity: 1;}
30% { opacity: 0;}
95% { opacity: 0;}
100% { opacity: 1;}
}
#-o-keyframes slideshow {
25% { opacity: 1;}
30% { opacity: 0;}
95% { opacity: 0;}
100% { opacity: 1;}
}
#keyframes slideshow {
25% { opacity: 1;}
30% { opacity: 0;}
95% { opacity: 0;}
100% { opacity: 1;}
}
<div id="img1" class="imgbox" style="background-image: url('http://img2.netcarshow.com/Ford-GT90_Concept_1995_800x600_wallpaper_01.jpg');">
</div>
<div id="img2" class="imgbox" style="background-image: url('http://img2.netcarshow.com/Mercedes-Benz-SLR_McLaren_2004_800x600_wallpaper_02.jpg');">
</div>
<div id="img3" class="imgbox" style="background-image: url('http://img2.netcarshow.com/Porsche-911_Carrera_4S_2002_800x600_wallpaper_0d.jpg');">
</div>
.imgbox{
display: flex;
align-items: center;
height: 100%;
width: 100%;
background-position: center center;
background-size: cover;
}
#img1{
position: absolute;
z-index: 3;
animation: xfade 15s -0s infinite;
animation-timing-function: ease-in-out;
}
#img2{
position: absolute;
z-index: 2;
animation: xfade 15s -5s infinite;
animation-timing-function: ease-in-out;
}
#img3{
position: absolute;
z-index: 1;
animation: xfade 15s -10s infinite;
animation-timing-function: ease-in-out;
}
#keyframes xfade{
0% {opacity: 0;}
20% {opacity: 1;}
33% {opacity: 1;}
53% {opacity: 0;}
100% {opacity: 0;}
}
I just set up a jsfiddle with an updated version for you.
https://jsfiddle.net/87axbx1o/
Let me know if that works well for you

How to have two css animations in one tag

I am working with css animations and I have a series of animations with different css tags. I start at #water then go to other animations then I want to go back to #water with a different animation. This is my code:
#water {
position: relative;
left: 48px;
z-index: 1;
opacity: 0;
width: 197px;
-webkit-animation: squeez 2s 1s 1 forwards;
-moz-animation: squeez 2s 1s 1 forwards;
-o-animation: squeez 2s 1s 1 forwards;
-webkit-animation: fadeOut 10s 10s 1 forwards;
-moz-animation: fadeOut 10s 10s 1 forwards;
-o-animation: fadeOut 10s 10s 1 forwards;
}
It does not work how I want it to. The code is disregarding the first animation "squeez" and only doing the animation "fadeOut" which messes everything up. Any ideas on how to make this work?
You can comma-separate your animations, so you could do:
-webkit-animation: squeez 2s 1s 1 forwards, fadeOut 10s 10s 1 forwards;
-moz-animation: squeez 2s 1s 1 forwards, fadeOut 10s 10s 1 forwards;
-o-animation: squeez 2s 1s 1 forwards, fadeOut 10s 10s 1 forwards;
animation: squeez 2s 1s 1 forwards, fadeOut 10s 10s 1 forwards;
div {
-webkit-animation: squeez 2s 1s forwards, fadeOut 10s 5s forwards;
animation: squeez 2s 1s forwards, fadeOut 10s 5s forwards;
height: 100px;
width: 100px;
background: #F00;
}
#-webkit-keyframes squeez {
from {
width: 100px;
}
to {
width: 20px;
}
}
#-webkit-keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 0.5;
}
}
#keyframes squeez {
from {
width: 100px;
}
to {
width: 20px;
}
}
#keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 0.5;
}
}
<div>
</div>

CSS3 animation slideshow

Got a small img slideshow running with animation/keyframes, it has 4 images running 6 seconds each on a 24s infinite loop,
The problem is that when it runs through once, the transition is fine, once it has gone through the 4 images and repeats, there is a good 2-3 seconds after an image fades out and the next one fades in.
First time using animation and keyframes so i'm not 100% what i've done wrong. The slide show is running in a div called .slideshow
I've taken out most prefixes for space and readability:
/* CSS */
.slideshow figure:nth-child(4) {
-webkit-animation: xfade 24s 0s infinite;
animation: xfade 24s 0s infinite;
}
.slideshow figure:nth-child(3) {
-webkit-animation: xfade 24s 6s infinite;
animation: xfade 24s 6s infinite;
}
.slideshow figure:nth-child(2) {
-webkit-animation: xfade 24s 12s infinite;
animation: xfade 24s 12s infinite;
}
.slideshow figure:nth-child(1) {
-webkit-animation: xfade 24s 18s infinite;
animation: xfade 24s 18s infinite;
}
#keyframes "xfade" {
0% {
opacity: 1;
}
14% {
opacity: 1;
}
16% {
opacity: 0;
}
90% {
opacity: 0;
}
100% {
opacity: 1;
}
}
Not a duplicate, having a problem with a single image slideshow that loops fine for the first 24s, then a major 2-3 gap between images every time after..
Try changing the xfade animation to
#keyframes "xfade" {
0% {
opacity: 1;
}
25% {
opacity: 1;
}
26% {
opacity: 0;
}
100% {
opacity: 0;
}
}
Logically since the images are 4 the cycle should be 25%,