I have a row of pictures where I want to fade in one image after another.
.jumbotron > div > div picture > img{
animation: fadein 6s;
-moz-animation: fadein 6s; /* Firefox */
-webkit-animation: fadein 6s; /* Safari and Chrome */
-o-animation: fadein 6s; /* Opera */
}
#keyframes fadein {
from {
opacity:0;
}
to {
opacity:1;
}
}
#-moz-keyframes fadein { /* Firefox */
from {
opacity:0;
}
to {
opacity:1;
}
}
#-webkit-keyframes fadein { /* Safari and Chrome */
from {
opacity:0;
}
to {
opacity:1;
}
}
#-o-keyframes fadein { /* Opera */
from {
opacity:0;
}
to {
opacity: 1;
}
}
This code let's all images fade in at the same time.
I'm using typo3 with a template, the html structure is a bit complicated because of this - I'm sorry.
<section class="jumbotron">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div id="c1170" class="">
<div class="row">
<div class="col-xl-9 col-lg-9 col-md-9 col-sm-12 col-xs-12">
<div class=" ">
<div id="c1163" class="">
<div class="row">
<div class="col-xl-2 col-lg-2 col-md-2 col-sm-6 col-xs-6">
<div class=" ">
<div id="c1164" class="">
<div class="ce-textpic ce-left ce-above">
<div class="" >
<div class="row">
<div class=" col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 ">
<div class="ce-media">
<picture alt="Geigen3D_m_02.gif">
<video style="display: none;"><![endif]-->
<![CDATA[ orig Width: 123px ]]>
<![CDATA[ xs scale: 0.5, 544px, max: 272px]]>
<source srcset="fileadmin/images/buecher/erzaehlungen/Geigen3D_m_02.gif" media="(max-width: 544px)">
<![CDATA[ sm scale: 0.5, 768px, max: 384px]]>
<source srcset="fileadmin/images/buecher/erzaehlungen/Geigen3D_m_02.gif" media="(max-width: 768px)">
<![CDATA[ md scale: 0.125, 992px, max: 124px]]>
<source srcset="fileadmin/images/buecher/erzaehlungen/Geigen3D_m_02.gif" media="(max-width: 992px)">
<![CDATA[ lg scale: 0.125, 1200px, max: 150px]]>
<source srcset="fileadmin/images/buecher/erzaehlungen/Geigen3D_m_02.gif" media="(min-width: 992px)">
</video><![endif]-->
<img src="fileadmin/images/buecher/erzaehlungen/Geigen3D_m_02.gif"
alt="Geigen3D_m_02.gif "
title=""
class="img-fluid m-b-1 " />
</picture>
</div>
</div>
<div class="clearfix hidden-sm-up"></div>
<div class="hidden-xs-down clearfix hidden-md-up"></div>
<div class="hidden-sm-down clearfix hidden-lg-up"></div>
<div class="hidden-md-down clearfix hidden-xl-up"></div>
<div class="hidden-lg-down clearfix"></div>
</div>
</div>
<div class="ce-bodytext">
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-2 col-lg-2 col-md-2 col-sm-6 col-xs-6">
<div class=" ">
<div id="c1165" class="">
<div class="ce-textpic ce-left ce-above">
<div class="" >
<div class="row">
<div class=" col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 ">
<div class="ce-media">
<!--next picture begins-->
<picture alt="image.gif">
and so on, and so on...
All solutions are welcome (pure css solution would be great tho), thank you for reading!
Here's a CSS-only solution using an approach similar to what you're starting with. I've simplified the HTML and CSS to focus on the important parts.
The General Idea
Layout your images as you desire. In this case I've used a <ul> element with <li> elements to hold the images, and laid them out horizontally.
Add a fadeIn animation to the images.
Now here's the key, add a animation-delay for each image, dependent on it's number in the lineup. The first will have no delay. The 2nd, a 3 second delay. The 3rd, a 6 second delay, and so on. This timing comes from the animation-duration of 3s. After the first image has faded in, the 2nd will fade in. After the 2nd has faded in, the 3rd will fade in, etc, etc.
Unknown Number of Images?
If the number of images is unknown this approach can still be used, though it will mean creating a few CSS styles that may never be used. You'll need to create:
li:nth-child(N) > img {
animation-delay: [animation-duration * N]s;
}
for the maximum number of images you think you'll have. So if you might have 100 images, and the animation-duration is set to 3s, you'll create 100 of those snippets, all the way through:
li:nth-child(100) > img {
animation-delay: 300s;
}
Demo
ul {
position: relative;
width: 100%
}
li {
float: left;
width: 25%;
}
img {
width: 100%;
opacity: 0;
animation-name: fadeIn;
animation-duration: 3s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
li:nth-child(2) > img {
animation-delay: 3s;
}
li:nth-child(3) > img {
animation-delay: 6s;
}
li:nth-child(4) > img {
animation-delay: 9s;
}
li:nth-child(5) > img {
animation-delay: 12s;
}
li:nth-child(6) > img {
animation-delay: 15s;
}
li:nth-child(7) > img {
animation-delay: 18s;
}
li:nth-child(8) > img {
animation-delay:21s;
}
#keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css" rel="stylesheet"/>
<ul>
<li><img src="http://placehold.it/400?text=1" /></li>
<li><img src="http://placehold.it/400?text=2" /></li>
<li><img src="http://placehold.it/400?text=3" /></li>
<li><img src="http://placehold.it/400?text=4" /></li>
<li><img src="http://placehold.it/400?text=5" /></li>
<li><img src="http://placehold.it/400?text=6" /></li>
<li><img src="http://placehold.it/400?text=7" /></li>
<li><img src="http://placehold.it/400?text=8" /></li>
</ul>
Here's the same demo on Codepen.
My proposal is to add an animation delay to every img (div in my example) increasingly. divs start with opacity:0; , attached in a class in this case, then we need some JavaScript to remove that opacity property once the animation has finished.
$('div').on('animationend', function() {
$(this).removeClass('initial');
})
.initial {
opacity: 0;
}
div {
width: 100px;
height: 100px;
background: pink;
border: 1px solid;
float: left;
animation: fadein 6s;
-moz-animation: fadein 6s;
/* Firefox */
-webkit-animation: fadein 6s;
/* Safari and Chrome */
-o-animation: fadein 6s;
/* Opera */
}
div:nth-child(1) {
animation-delay: 0s;
}
div:nth-child(2) {
animation-delay: 6s;
}
div:nth-child(3) {
animation-delay: 12s;
}
div:nth-child(4) {
animation-delay: 18s;
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#-moz-keyframes fadein {
/* Firefox */
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#-webkit-keyframes fadein {
/* Safari and Chrome */
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#-o-keyframes fadein {
/* Opera */
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<div class="initial"></div>
<div class="initial"></div>
<div class="initial"></div>
<div class="initial"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Related
I'm trying to add animation using CSS3 but I'm having some issue.
Can someone please help me?
.cuv h5 {
font-size: 25px;
animation: fadein 1.5s;
-moz-animation: fadein 2s;
-webkit-animation: fadein 2s;
-o-animation: fadein 2s;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<section class="cuv">
<div class="content">
<div class="container">
<div class="row">
<h5>Help Me</h5>
</div>
</div>
</div>
</section>
I got your issue. Please try with this. It would works.
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
I have the following HTML:
<div class="rating">
<div class="star active"></div>
<div class="star active"></div>
<div class="star active"></div>
<div class="star"></div>
<div class="star"></div>
</div>
Output:
★★★☆☆
How do I animate in CSS the active stars, one by one?
I tried:
.star {
transition: background-color 0.5s ease;
background-color: #eee;
}
.star.active {
background-color: #000;
}
This transitions the color of all the active stars at once. How to I transition the active stars one by one, from left to right?
I am trying to achieve this without JS. The rating score can be anything. Also the range can be any number (there could be 3 or 5 or 8 or 10 stars, etc)
Because of the active class is already assigned, it's better to use animation instead of transition.
.star {
background-color: #eee;
}
.star.active {
animation: star-pop 0.5s ease forwards;
}
#keyframes star-pop {
to {
background-color: #000;
}
}
Then you can give a different animation-delay for different nth-child:
.star.active:nth-child(1) {
animation-delay: 0s;
}
.star.active:nth-child(2) {
animation-delay: 0.5s;
}
.star.active:nth-child(3) {
animation-delay: 1s;
}
.star.active:nth-child(4) {
animation-delay: 1.5s;
}
.star.active:nth-child(5) {
animation-delay: 2s;
}
/* ... */
If you have a css precompiler(such as sass), you can achieve it with a loop:
.star.active {
// change the number 5 to maximum possible stars(8, 10, etc.)
#for $i from 1 through 5 {
&:nth-child(#{$i}) {
animation-delay: #{($i - 1) * 0.5}s;
}
}
}
.star {
display: inline-block;
width: 40px;
height: 40px;
border: solid 1px #000;
background-color: #eee;
}
.star.active {
animation: star-pop 0.5s ease forwards;
}
.star.active:nth-child(1) {
animation-delay: 0s;
}
.star.active:nth-child(2) {
animation-delay: 0.5s;
}
.star.active:nth-child(3) {
animation-delay: 1s;
}
.star.active:nth-child(4) {
animation-delay: 1.5s;
}
.star.active:nth-child(5) {
animation-delay: 2s;
}
#keyframes star-pop {
to {
background-color: #000;
}
}
<div class="rating">
<div class="star active"></div>
<div class="star active"></div>
<div class="star active"></div>
<div class="star"></div>
<div class="star"></div>
</div>
I have 9 logos as of now and that logo I am displaying in the list order. Now what I am doing is, I have to display the first 3 logos and wait for some second then hide that 3 logos and display the next 3 logos again wait for some second, and display the next 3 logos. I need infinite this.
For example:
On the page load display first 3 logo
1 2 3
//wait for the second
1 2 3 // hide this
4 5 6 // display this
7 8 9 // hide this
//wait for second
1 2 3 // hide this
4 5 6 // hide this
7 8 9 // display this
// wait for second
1 2 3 // display this
4 5 6 // hide this
7 8 9 // hide this
I need infinite.
I tried this code but it's not working.
ul {
list-style: none;
width: 100%;
position: relative;
}
ul li {
display: inline-block;
width: 33%;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
opacity: 0;
animation-name: fadeIn;
}
ul li img {
width: 250px;
}
/*Animated Logos*/
#keyframes fadeIn {
0% {
opacity: 0;
}
6% {
opacity: 1;
}
27% {
opacity: 1;
}
33% {
opacity: 0;
}
}
.row--animated li:nth-of-type(-n+3) {
animation-duration: 4s;
}
.row--animated li:nth-child(4),
.row--animated li:nth-child(5),
.row--animated li:nth-child(6) {
animation-duration: 6s;
}
.row--animated li:nth-last-child(-n+3) {
animation-duration: 8s;
/*position: absolute;*/
}
<div class="row--animated">
<ul>
<li><img src="//placehold.it/450x280?text=Image 1" /></li>
<li><img src="//placehold.it/450x280?text=Image 2" /></li>
<li><img src="//placehold.it/450x280?text=Image 3" /></li>
<li><img src="//placehold.it/450x280?text=Image 4" /></li>
<li><img src="//placehold.it/450x280?text=Image 5" /></li>
<li><img src="//placehold.it/450x280?text=Image 6" /></li>
<li><img src="//placehold.it/450x280?text=Image 7" /></li>
<li><img src="//placehold.it/450x280?text=Image 8" /></li>
<li><img src="//placehold.it/450x280?text=Image 9" /></li>
</ul>
</div>
Would you help me out in this?
You can use display-grid to force the elements in a single row.
And you can play with the properties of the animation to get this effect, but the duration of the animation should be the same for all the elements; what is changing from one to the other is the delay , to make then be at different stages of the animation:
ul {
list-style: none;
width: 100%;
position: relative;
display: grid;
}
ul li {
display: inline-block;
width: 30%;
opacity: 0.2;
animation: fadeInSlow ease-in-out 6s infinite;
background-color: blue;
height: 50px;
grid-row: 1;
}
#keyframes fadeIn {
0% {
opacity: 0;
}
6% {
opacity: 1;
}
27% {
opacity: 1;
}
33% {
opacity: 0;
}
}
#keyframes fadeInSlow {
0% {
opacity: 0;
}
12% {
opacity: 1;
}
21% {
opacity: 1;
}
33%, 100% {
opacity: 0;
}
}
li:nth-child(4),
li:nth-child(5),
li:nth-child(6) {
animation-delay: -4s;
}
li:nth-child(7),
li:nth-child(8),
li:nth-child(9) {
animation-delay: -2s;
}
li:nth-child(3n+1) {
grid-column: 1;
}
li:nth-child(3n+2) {
grid-column: 2;
}
li:nth-child(3n+3) {
grid-column: 3;
}
<div class="row--animated">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</div>
Update: this snippet is what I think you want, note that I changed the HTML a bit so that I can manipulate the elements size and display, Implemented with CSS3 only, heavily inspire by this codepen:
.slider {
width: 900px;
margin: 0 auto;
}
.slide {
position: absolute;
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 10px;
}
.slide img {
width: 100;
height: auto;
}
.slide1 {
animation: fade 8s infinite;
-webkit-animation: fade 8s infinite;
}
.slide2 {
animation: fade2 8s infinite;
-webkit-animation: fade2 8s infinite;
}
.slide3 {
animation: fade3 8s infinite;
-webkit-animation: fade3 8s infinite;
}
#keyframes fade {
0% {
opacity: 1;
}
33.333% {
opacity: 0;
}
66.666% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fade2 {
0% {
opacity: 0;
}
33.333% {
opacity: 1;
}
66.666% {
opacity: 0;
}
100% {
opacity: 0;
}
}
#keyframes fade3 {
0% {
opacity: 0;
}
33.333% {
opacity: 0;
}
66.666% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class='slider'>
<div class='slide slide1'>
<div class="container">
<img src="//placehold.it/300x280?text=Image 1" />
</div>
<div class="container">
<img src="//placehold.it/300x280?text=Image 2" />
</div>
<div class="container">
<img src="//placehold.it/300x280?text=Image 3" />
</div>
</div>
<div class='slide slide2'>
<div class="container">
<img src="//placehold.it/300x280?text=Image 4" />
</div>
<div class="container">
<img src="//placehold.it/300x280?text=Image 5" />
</div>
<div class="container">
<img src="//placehold.it/300x280?text=Image 6" />
</div>
</div>
<div class='slide slide3'>
<div class="container">
<img src="//placehold.it/300x280?text=Image 7" />
</div>
<div class="container">
<img src="//placehold.it/300x280?text=Image 8" />
</div>
<div class="container">
<img src="//placehold.it/300x280?text=Image 9" />
</div>
</div>
</div>
</body>
</html>
I am trying to figure out how I can write a CSS animation that allows an image (id: slam) to suddenly appear on screen and cover all of the content without displacing any of the text. So far, this is what I have:
HTML:
body{
height: 100%;
}
div{
overflow: auto;
text-align: center;
}
#-webkit-keyframes slam-animation {
0% {
opacity: 0;
-webkit-transform: scale(10);
}
100% {
opacity: 1;
-webkit-transform: rotate(-30deg) scale(1);
}
}
#slam {
-webkit-animation-name: slam-animation;
-webkit-animation-duration: 1s;
-webkit-animation-direction: normal;
-webkit-animation-timing-function: linear;
-webkit-animation-fill-mode: forwards;
}
<body>
<img id="slam" src="assets/images/Undesirable.jpg" alt = "undesirable">
<header>
<h1>Text</h1>
</header>
<div class="main_game">
<p>Stuff</p>
<div class = "col-xs-2">
</div>
<div class = "left_box col-xs-4">
<p>Stuff</p>
</div>
<div class = "right_box col-xs-4">
<p>Stuff</p>
</div>
<div class = "col-xs-2">
</div>
</div>
</body>
Use position:absolute to your image.
Using absolute position the element is removed from the normal document flow; no space is created for the element in the page layout i.e. it will not affect the position of other elements.
Reference Link to understand position absolute
Stack Snippet
body {
height: 100%;
}
.main_game div {
text-align: center;
}
.main {
position: relative;
}
#-webkit-keyframes slam-animation {
0% {
opacity: 0;
-webkit-transform: scale(10);
}
100% {
opacity: 1;
-webkit-transform: rotate(-30deg) scale(1);
}
}
img#slam {
position: absolute;
top: 0;
left: 0;
}
#slam {
-webkit-animation-name: slam-animation;
-webkit-animation-duration: 1s;
-webkit-animation-direction: normal;
-webkit-animation-timing-function: linear;
-webkit-animation-fill-mode: forwards;
}
<div class="main">
<img id="slam" src="http://via.placeholder.com/350x350" alt="undesirable">
<header>
<h1>Text</h1>
</header>
<div class="main_game">
<p>Stuff</p>
<div class="col-xs-2">
</div>
<div class="left_box col-xs-4">
<p>Stuff</p>
</div>
<div class="right_box col-xs-4">
<p>Stuff</p>
</div>
<div class="col-xs-2">
</div>
</div>
</div>
I am working on pure CSS carousel that changes 4 divs with pictures and hyperlinks by dissolving them over blue background.
It works fine in IE10/11, Opera 15, Mozila 23, Safari 5.1.7 (win), Safari ? (osx108).
When running in Chrome 29 it is almost ok except one issue. If it is opened in 2+ browser tabs it looses synchronisation and skips images almost immediately. If it is opened in 2+ browser windows everything is ok.
It is getting broken in the same way in Safari on iPad2.
Is it a browser or code problem?
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Carousel v0</title>
<link href="carousel.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Carousel Start -->
<div class="carousel-items">
<div id="carousel-item-1" class="carousel-item">
<a class="carousel-item-text" href="#" title="Go to Showcase Item 1">
<span class="carousel-item-title">Showcase Item 1 Title</span>
<span class="carousel-item-description">Brief description or introduction into Showcase Item 1.</span>
</a>
</div>
<div id="carousel-item-2" class="carousel-item">
<a class="carousel-item-text" href="#" title="Go to Showcase Item 2">
<span class="carousel-item-title">Showcase Item 2 Title</span>
<span class="carousel-item-description">Brief description or introduction into Showcase Item 2.</span>
</a>
</div>
<div id="carousel-item-3" class="carousel-item">
<a class="carousel-item-text" href="#" title="Go to Showcase Item 3">
<span class="carousel-item-title">Showcase Item 3 Title</span>
<span class="carousel-item-description">Brief description or introduction into Showcase Item 3.</span>
</a>
</div>
<div id="carousel-item-4" class="carousel-item">
<a class="carousel-item-text" href="#" title="Go to Showcase Item 4">
<span class="carousel-item-title">Showcase Item 4 Title</span>
<span class="carousel-item-description">Brief description or introduction into Showcase Item 4.</span>
</a>
</div>
</div>
<!-- Carousel Finish -->
</body>
</html>
CSS:
/* Container to position carousel composition */
.carousel-items {
overflow: hidden;
width: 923px;
height: 355px;
background: rgba(0,19,127,0.3);
}
/* Deafault position of carousel items */
.carousel-item {
position: absolute!important;
width: 923px;
height:355px;
opacity: 0;
-webkit-animation: colorDissolve 24s linear infinite;
-moz-animation: colorDissolve 24s linear infinite;
-ms-animation: colorDissolve 24s linear infinite;
animation: colorDissolve 24s linear infinite;
}
/* Backgrounds to carousel items */
#carousel-item-1{background-image:url('one.jpg');}
#carousel-item-2{background-image:url('two.jpg');}
#carousel-item-3{background-image:url('three.jpg');}
#carousel-item-4{background-image:url('four.jpg');}
/* Animation delay for carousel item 2 */
.carousel-item:nth-child(2) {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s;
}
/* Animation delay for carousel item 3 */
.carousel-item:nth-child(3) {
-webkit-animation-delay: 12s;
-moz-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s;
}
/* Animation delay for carousel item 4 */
.carousel-item:nth-child(4) {
-webkit-animation-delay: 18s;
-moz-animation-delay: 18s;
-ms-animation-delay: 18s;
animation-delay: 18s;
}
/* Appearance of carousel item description - Initial style*/
.carousel-item-text {
position:relative;
display:block;
top:285px;
z-index: 1500;
width: 923px;
height: 70px;
overflow: hidden;
color:#ffffff;
text-decoration:none;
background: rgba(0,19,127,0.3);
-webkit-transition: all 750ms ease;
-moz-transition: all 750ms ease;
-o-transition: all 750ms ease;
-ms-transition: all 750ms ease;
transition: all 750ms ease;
}
/* Appearance of carousel item description - Item hover style */
.carousel-item:hover > .carousel-item-text {
top:205px;
height: 150px;
}
/* Title of carousel item */
.carousel-item-title {
position:relative;
padding-left:20px;
font-size:xx-large;
line-height:70px;
letter-spacing: 2px;
}
/* Description of carousel item */
.carousel-item-description {
position:relative;
display:block;
width:783px;
padding-left:20px;
line-height:130%;
font-size:x-large;
}
/* The keyframes calculations are based on assumption of 4 items in the carousel. */
#-webkit-keyframes colorDissolve {
0%, 27%, 100% { opacity: 0; }
2%, 25% { opacity: 1; z-index:1000;}
}
#-moz-keyframes colorDissolve {
0%, 27%, 100% { opacity: 0; }
2%, 25% { opacity: 1; z-index:1000;}
}
#-ms-keyframes colorDissolve {
0%, 27%, 100% { opacity: 0; }
2%, 25% { opacity: 1; z-index:1000;}
}
#keyframes colorDissolve {
0%, 27%, 100% { opacity: 0; }
2%, 25% { opacity: 1; z-index:1000;}
}