I am creating a slideshow using keyframes.
My issue lies in the fact that only the first image actually shows, the other 4 are just ignored as you can see in my snippet.
I have looked at my CSS and don't think any of it is "useless" (correct me if there is anything unnecessary) and otherwise, I am unsure why the images wouldn't show.
Here is a working snippet of what I have done so far:
carousel {
max-width: 100%;
height: 500px;
max-height: 500px;
margin-bottom: 20px;
position: relative;
overflow: hidden;
display: block;
}
carousel img {
max-width: 100%;
width: 1920px;
height: auto;
max-height: 500px;
position: absolute;
left: 0;
top: 0;
animation: slide 20s ease-in-out infinite;
}
#keyframes slide {
0% {
left: 0;
}
100% {
left: -500%;
}
}
<carousel>
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
</carousel>
You need to manually push one image after anothe, because you have positin: absolute they are each on another , because left: 0
carousel {
max-width: 100%;
height: 500px;
max-height: 500px;
margin-bottom: 20px;
position: relative;
overflow: hidden;
display: block;
}
carousel img {
max-width: 100%;
width: 1920px;
height: auto;
max-height: 500px;
position: absolute;
left: 0;
top: 0;
animation: slide 20s ease-in-out infinite;
}
carousel img:nth-child(2) {
margin-left: 100%;
}
carousel img:nth-child(3) {
margin-left: 200%;
}
carousel img:nth-child(4) {
margin-left: 300%;
}
carousel img:nth-child(5) {
margin-left: 400%;
}
#keyframes slide {
0% {
left: 0;
}
100% {
left: -500%;
}
}
<carousel>
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080" alt="carousel-img">
</carousel>
The problem is because you are positioning all the images absolutely at top: 0px, left: 0px of the container (meaning, they are all one over the other) and also adding the same animation to them at the same time. Because of this all images move from left: 0% to left: -500% at the same time and so you get to see only one image.
I am not quite sure what effect you are wanting to achieve and so I'll give you two options. If what you want is a film-roll like effect then remove position: absolute oncarousel img, get them to display on the same line using white-space: nowrap on the parent and then animate parent's margin-left.
carousel {
max-width: 100%;
height: 500px;
max-height: 500px;
margin-bottom: 20px;
position: relative;
overflow: hidden;
display: block;
white-space: nowrap;
animation: slide 20s ease-in-out infinite;
}
carousel img {
height: auto;
max-height: 500px;
}
#keyframes slide {
0% {
margin-left: 0;
}
100% {
margin-left: -500%;
}
}
<carousel>
<img src="http://www.lorempixel.com/1920/1080/nature/1" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/2" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/3" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/4" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/5" alt="carousel-img">
</carousel>
Or, if you want to achieve an effect where each image is stacked one below the other but they start to move only after the previous image (the one above it) has completely moved out then add animation-delay to each image element such that it is equal to the amount of time required for the images above it to complete their animation. Also, change animation-duration to the total amount of time required for all 5 images to complete their animation.
carousel {
max-width: 100%;
height: 500px;
max-height: 500px;
margin-bottom: 20px;
position: relative;
overflow: hidden;
display: block;
}
carousel img {
max-width: 100%;
width: 1920px;
height: auto;
max-height: 500px;
position: absolute;
left: 0;
top: 0;
animation: slide 100s ease-in-out infinite;
}
carousel img:nth-child(1){
animation-delay: 80s;
}
carousel img:nth-child(2){
animation-delay: 60s;
}
carousel img:nth-child(3){
animation-delay: 40s;
}
carousel img:nth-child(4){
animation-delay: 20s;
}
#keyframes slide {
0% {
left: 0;
}
20% {
left: -100%;
}
}
<carousel>
<img src="http://www.lorempixel.com/1920/1080/nature/1" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/2" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/3" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/4" alt="carousel-img">
<img src="http://www.lorempixel.com/1920/1080/nature/5" alt="carousel-img">
</carousel>
Related
I'm trying to create a sequential text animation. One line, then the next, then the next. But it animates all three lines at the same time.
.autotype {
overflow: hidden;
white-space: nowrap;
}
.autotype {
animation: autotype 8s steps(10, end);
animation-iteration-count: infinite;
}
#keyframes autotype {
from {
width: 0px;
}
}
#keyframes autotype {
0% {
width: 0px;
}
20% {
width: 70px;
}
40% {
width: 140px;
}
60% {
wdith: 210px;
}
80%. {
width: 280px;
}
100% {
width: 500px;
}
}
.alignnone {
height: 20px;
width: 50px;
position: relative;
top: 4px;
}
<div class="autotype">.
<p>Hello, and welcome to
<img src="http://4309.co.uk/wp-
content/uploads/2020/01/
Screenshot_20200110_150836-
300x115.jpg" alt="" width="300" height="115" class="alignnone size-medium
wp-image-8431" />Feel free to look</p>
<p>around the site and contact us via the form<br> on the contact page</div>
So how do i animate it so that it reveals the first line, and only when this is fully revealed begins the second and so on. I've tried using height in the animation itself but, whilst this works for the first line, when it goes higher for the next line they've already rendered.
Since CSS cannot detect characters, I suggest you to
Wrap the lines inside a separate class autotype1, autotype2 and autotype3.
Hide the other lines initially with width: 0 or opacity: 0;
Use animation-delay with timing like 2n, 3n to make it sequential.
If you want to make it infinite, you might want to add a bit of JS with the help of these answers: CSS animation delay in repeating
.autotype {
overflow: hidden;
white-space: nowrap;
}
.autotype {
animation: autotype 4s steps(10, end);
animation-fill-mode: forwards;
}
.autotype2 {
width: 0;
animation-delay: 4s;
margin-bottom: 0;
}
.autotype3 {
width: 0;
animation-delay: 8s;
margin-top: 0;
}
#keyframes autotype {
from {
width: 0px;
}
}
#keyframes autotype {
0% {
width: 0px;
}
20% {
width: 70px;
}
40% {
width: 140px;
}
60% {
width: 210px;
}
80%. {
width: 280px;
}
100% {
width: 500px;
}
}
.alignnone {
height: 20px;
width: 50px;
position: relative;
top: 4px;
}
<div>.
<p class="autotype autotype1">Hello, and welcome to
<img src="http://4309.co.uk/wp-
content/uploads/2020/01/
Screenshot_20200110_150836-
300x115.jpg" alt="" width="300" height="115" class="alignnone size-medium
wp-image-8431" />Feel free to look</p>
<p class="autotype autotype2">around the site and contact us via the form<br>
</p>
<p class="autotype autotype3"> on the contact page</p>
</div>
I have an image slideshow that I am trying to centre in the viewport, regardless of the viewport's width. This is easily achieved if the viewport is wider than the image by using margin: auto;, however, when the viewport is narrower than the image, like on a tablet in portrait mode, the image butts up against the left margin and does not centre.
Centred in landscape mode:
Centred in portrait mode:
This is the HTML:
<div id="slidebound">
<div class="slider">
<img src="images/slider/slide04.png" alt=""/>
<img src="images/slider/slide03.png" alt=""/>
<img src="images/slider/slide02.png" alt=""/>
<img src="images/slider/slide01.png" alt=""/>
</div>
</div>
This is the CSS:
#slidebound {
width: 100%;
height: 300px;
overflow: hidden;
}
.slider {
width: 1024px;
height: 300px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.slider img {
position: absolute;
animation: slider 32s infinite;
opacity: 0;
width: 100%;
height: auto;
}
#keyframes slider {25% {opacity: 1;} 40% {opacity: 0;}}
.slider img:nth-child(4) {animation-delay: 0s;}
.slider img:nth-child(3) {animation-delay: 8s;}
.slider img:nth-child(2) {animation-delay: 16s;}
.slider img:nth-child(1) {animation-delay: 24s;}
As per i understand, you want your image to appear in center, no-matter what the screen size is. For this you can try below code:
#slidebound {
width: 100%;
height: 300px;
overflow: hidden;
display: flex;
justify-content: center;
}
.slider {
width: 1024px;
height: 300px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.slider img {
position: absolute;
animation: slider 32s infinite;
opacity: 0;
width: 100%;
height: auto;
}
#keyframes slider {25% {opacity: 1;} 40% {opacity: 0;}}
.slider img:nth-child(4) {animation-delay: 0s;}
.slider img:nth-child(3) {animation-delay: 2s;}
.slider img:nth-child(2) {animation-delay: 3s;}
.slider img:nth-child(1) {animation-delay: 4s;}
<div id="slidebound">
<div class="slider">
<img src="http://abload.de/img/a6aawu.jpg" alt=""/>
<img src="https://nxworld.net/example/css-image-hover-effects/pic01.jpg" alt=""/>
<img src="http://abload.de/img/a6aawu.jpg" alt=""/>
<img src="https://nxworld.net/example/css-image-hover-effects/pic01.jpg" alt=""/>
</div>
You can use flexbox. But as a alternative, as you know the height and width you can use position and negative margins:
position:absolute;
left:50%;
margin-left:-512px;
top:50%;
margin-top:-150px;
See it in action.
Are you ok in using flex for your case? It depends on what browsers you need to support. You can check it out using caniuse.
In the meantime, here is a sample
https://codepen.io/hellouniverse/pen/QxwNWv
where I have centred one image both vertically and horizontally to show the way
#slidebound {
height: 100vh;
}
.slider {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
margin: 0 auto;
height: inherit;
}
<div id="slidebound">
<div class="slider">
<img src="https://naomisimson.com/wp-content/uploads/image-placeholder.jpg" alt="" />
</div>
</div>
I wan to make animation from left to right (animation start in invisible area like left: -100px) and end in invisible area too (right: -100px) I am using this code which works but not correctly on different sizes of screens becuase is in %. And i need to remake it but i dont know how.
.ip_first_block {
width: 100%;
height: 100%;
}
section {
position: relative;
overflow: hidden;
}
.ip_welcome_text {
width: 100%;
height: 70%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.astronaut1 {
position: relative;
animation: lefttoright 10s;
animation-fill-mode: forwards;
}
#keyframes lefttoright {
from {
transform: translateX(-1500%);
}
to {
transform: translateX(2200%);
}
}
<section style="height:100%;">
<div class="ip_first_block" id="ifb">
<div class="ip_welcome_text">
<div class="astronaut1">
<img src="images/astronaut.svg" height="70px" ; width="70px;" />
</div>
</div>
</div>
</section>
It's easier if you animate the position, e.g. left property:
body {margin: 0}
.astronaut1 {
overflow: hidden;
}
img {
position: relative;
left: -70px; /* starting point; needs to be at least the img width to hide it */
animation: lefttoright 10s forwards;
}
#keyframes lefttoright {
to {left: 100%} /* cover the entire parent width */
}
<div class="astronaut1">
<img src="http://placehold.it/70x70" alt="" height="70" width="70">
</div>
Hello guys I would like to know how can I add text in my image slider. I would like to add text to each image. I could do it in Photoshop, but I wont to be able to edit the text in the HTML in future in case it needs changing. How would I go about doing that?
#keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -115%; }
45% { left: -115%; }
50% { left: -225%; }
70% { left: -225%; }
75% { left: -335%; }
95% { left: -335%; }
100% { left: -445%; }
}
body { margin: 0; }
div#slider { overflow: hidden; }
div#slider figure img { width: 22%; float: left; }
div#slider figure {
position: relative;
width: 500%;
height: 34px;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}
#slider {
max-width: 75%;
left: 12.5%;
max-height: 55%;
}
</div>
previously -->
<div class="container center-block">
<div class="col-xs-12" id="slider">
<figure>
<img src="imgs/rdp.jpg" class="img-responsive" />
<img src="imgs/wires.jpg" class="img-responsive" />
<img src="imgs/speed.jpg" class="img-responsive" />
<img src="imgs/tech.jpg" class="img-responsive" />
</figure>
</div>
</div>
There is a hand icon that I am using on my page and It is directing to three images.I want an animation on this icon, where It should move from initial state to right, then from initial state to left and so forth.In other words, it should cover all the three images.
I have tried myself also, it is moving initial state to right but not from initial state to left.Here is my code snippet down below:
div#skill .logos {
padding: 20px 0;
}
.logos>img {
margin-right: 10px;
}
.move {
position: relative;
animation: move 2s infinite;
animation-direction: alternate-reverse;
}
/*Animation on hand*/
#keyframes move {
0% {
left: 0px;
right: 0px;
}
50% {
left: 60px;
right: 0;
}
100% {
left: 0px;
right: 60px;
}
}
<img class="move center-block" src="img/icons/hand-finger-pointing-down.svg" width="60" height="60">
<div class="logos text-center">
<img src="img/icons/adobe-photoshop.png" width="50" height="50">
<img src="img/icons/bootstrap-4.svg" width="50" height="50">
<img src="img/icons/Sublime_Text_Logo.png" width="50" height="50">
</div>
Please guide me and thank you in advance!
I posted another answer with your exact mark up. You were using both right and left. When you're animating, you should make sure you're animating on the same property/properties, which in this case is left.
div#skill .logos {
padding: 20px 0;
}
.logos, .move-container {
max-width: 200px;
}
.logos>img {
margin-right: 10px;
}
.move {
position: relative;
animation: move 5s infinite;
}
/*Animation on hand*/
#keyframes move {
0% {
left: 60px;
}
50% {
left: 0px;
}
75% {
left: 120px;
}
100% {
left: 60px;
}
}
<div class="move-container">
<img class="move center-block" src="img/icons/hand-finger-pointing-down.svg" width="60" height="60">
</div>
<div class="logos text-center">
<img src="img/icons/adobe-photoshop.png" width="50" height="50">
<img src="img/icons/bootstrap-4.svg" width="50" height="50">
<img src="img/icons/Sublime_Text_Logo.png" width="50" height="50">
</div>
The main difference I think is that I was more specific with my animation. I specified that it should start from center, go to left, go back to center, go to right, then go back to center.
.images {
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
}
img {
max-width: 30%;
height: auto;
z-index: 1;
}
.icon-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
}
.icon-container img {
background-color: #fff;
z-index: 2;
width: 30px;
height: 30px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: move 6s infinite;
}
#keyframes move {
0% {left: 50%}
25% {left: 15%}
50% {left: 50%}
75% {left: 85%}
100% {left: 50%}
}
<div class="images">
<img src="http://img06.deviantart.net/25de/i/2012/134/3/1/037_by_koko_stock-d4zq28i.jpg" />
<img src="http://www.apimages.com/Images/Ap_Creative_Stock_Header.jpg"/>
<img src="http://platowebdesign.com/articles/wp-content/uploads/2014/10/public-domain-images-free-stock-photos-light-sky-silo-windows-lillyphotographer-1024x684.jpg"/>
<div class="icon-container">
<img class="https://cdn3.iconfinder.com/data/icons/touch-gesture-outline/512/double_click_touch_click_finger_hand_select_gesture-512.png"/>
</div>
</div>