Sequential CSS3 animation - animation

I'm wondering if it is possible to fade in a list of items sequentially using CSS3 only?
HTML would be something like this:
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
<li>item 7</li>
<li>item 8</li>
<li>item 9</li>
<li>item 10</li>
<li>item 11</li>
<li>item 12</li>
<li>item 13</li>
<li>item 14</li>
<li>item 15</li>
</ul>
And when the UL gets the class "fadeout" it would be cool if first "item1" fades out (during 2 seconds) once this is finished fade out the next one("item2") and so on until all items are faded out.
I know how to do this using jQuery but it would be nice if this was possible using CSS3 only? Any ideas if this could be possible?
EDIT: I'm really looking for a solution that also works when you don't know how many items are in the list. it could be 1 it could be a 100?
EDIT: Apparently making this for a variable amount of elements is impossible using CSS only, so the best CSS solution is for a fixed number of items. Otherwise you will have to use JS.
Thx for the responses!

This would work:
HTML:
<ul class="fadeout">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
CSS:
ul.fadeout li:nth-child(1){
-webkit-animation: fadeOut 2s linear forwards;
}
ul.fadeout li:nth-child(2){
-webkit-animation: fadeOut 2s linear 2s forwards;
}
ul.fadeout li:nth-child(3){
-webkit-animation: fadeOut 2s linear 4s forwards;
}
ul.fadeout li:nth-child(1){
-webkit-animation: fadeOut 2s linear forwards;
}
#-webkit-keyframes fadeOut {
0% { opacity: 1; }
100% { opacity: 0; }
}
http://jsfiddle.net/fGAZr/

This is something I wouldn't recommend, as with all the vendor extensions it would get extremely verbose. It would be possible to auto-generate the code with scss, but I wouldn't bother.
ul li { transition: opacity 200ms linear;}
ul.fadeout li {opacity: 0;}
ul.fadeout li:nth-child(1) { transition-delay: 0 }
ul.fadeout li:nth-child(2) { transition-delay: 0.1s }
ul.fadeout li:nth-child(3) { transition-delay: 0.2s }
ul.fadeout li:nth-child(4) { transition-delay: 0.3s }
ul.fadeout li:nth-child(5) { transition-delay: 0.4s }
ul.fadeout li:nth-child(6) { transition-delay: 0.5s }
ul.fadeout li:nth-child(7) { transition-delay: 0.6s }
ul.fadeout li:nth-child(8) { transition-delay: 0.7s }
ul.fadeout li:nth-child(9) { transition-delay: 0.8s }
ul.fadeout li:nth-child(10) { transition-delay: 0.9s }
ul.fadeout li:nth-child(11) { transition-delay: 1s }
ul.fadeout li:nth-child(12) { transition-delay: 1.1s }
ul.fadeout li:nth-child(13) { transition-delay: 1.2s }
ul.fadeout li:nth-child(14) { transition-delay: 1.3s }
ul.fadeout li:nth-child(15) { transition-delay: 1.4s }
You can view a webkit only example here: http://jsfiddle.net/kUQj7/

Related

Stagger cycled images in slideshow

I'm trying to create a slideshow/carousel but rather than scroll, they fade in/out. I've got them to cycle through the images, with 3 images per cycle but I wanted to stagger each image from left to right.
https://codepen.io/fearnaught/pen/BarOVqr
<div class="logo-container">
<img src="https://www.placecage.com/300/120" alt="1">
<img src="https://www.placecage.com/300/121" alt="2">
<img src="https://www.placecage.com/300/122" alt="3">
<img src="https://www.placecage.com/300/123" alt="4">
</div>
<div class="logo-container two">
<img src="https://www.placecage.com/301/123" alt="6">
<img src="https://www.placecage.com/301/122" alt="5">
<img src="https://www.placecage.com/301/121" alt="7">
<img src="https://www.placecage.com/301/120" alt="8">
</div>
<div class="logo-container three">
<img src="https://www.placecage.com/302/122" alt="9">
<img src="https://www.placecage.com/302/120" alt="10">
<img src="https://www.placecage.com/302/123" alt="11">
<img src="https://www.placecage.com/302/121" alt="12">
</div>
.logo-container {
position: relative;
}
.logo-container.two {
left:320px
}
.logo-container.three {
left: 640px
}
.logo-container img {
position: absolute;
animation-name: multiple-logo-crossfade;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 8s;
left: 0;
background-color: var(--cream);
}
.logo-container img:nth-of-type(1) {
animation-delay: 6s;
}
.logo-container img:nth-of-type(2) {
animation-delay: 4s;
}
.logo-container img:nth-of-type(3) {
animation-delay: 2s;
}
.logo-container img:nth-of-type(4) {
animation-delay: 0;
}
#keyframes multiple-logo-crossfade {
0% {
opacity: 1;
}
17% {
opacity: 1;
}
25% {
opacity: 0;
}
82% {
opacity: 0;
}
100% {
opacity: 1;
}
}
I've tried adding different delays to the middle and right images, but it doesn't seem to be a smooth infinite cycle.

Image doesnt display in Chrome it does in Safari & Firefox

I have a problem with a image I added to the header It doesn't seem to display in Chrome but is does display on Safari and Firefox. I have 3 black banners/flags on the top left of the screen. The middle doesnt display on chrome. Does anyone have a suggestion or an idea why it doesn't display?
header.php:
<div class="header_inner clearfix">
<div class="marketing-top">
<img src="/wp-content/uploads/2015/04/Banner-header-marketing.png" alt="marketing">
<img class="space" src="/wp-content/uploads/2015/04/Banner-header-design.png" alt="design">
<div class="header-img animated swing">
<img src="/wp-content/uploads/2015/05/banner-header-web-design.jpg" alt="webdesign">
</div>
</div>
css:
.marketing-top {
padding-left: 180px;
position: absolute;
float: left;
left: 100px;
}
.marketing-top .space{
position: absolute;
float:left;
left:280px;
bottom:57px;
}
.header-img {
position: absolute;
float:left;
left:230px;
bottom:0px;
}
#media screen and (max-width: 1250px) {
.marketing-top{
display: none;
}
}
.swing {
animation-name: swing;
transform-origin: center top 0;
}
.animated {
animation-duration: 5s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
}
#keyframes swing {
0% {
transform: rotate(0deg);
animation-timing-function: ease-in-out;
}
20% {
transform: rotate(1deg);
animation-timing-function: ease-in-out;
}
40% {
transform: rotate(-1deg);
animation-timing-function: ease-in-out;
}
60% {
transform: rotate(0.5deg);
animation-timing-function: ease-in-out;
}
80% {
transform: rotate(-0.5deg);
animation-timing-function: ease-in-out;
}
100% {
transform: rotate(0deg);
animation-timing-function: ease-in-out;
}
}
Thanks in advance!
Vonwelzen
Related URL: http://www.elephantdesign.nl
6 hours ago
Its because width of .header-img is 0 in your case. Explicitly assign a width greater than image width
.header-img{
width:50px;
}

issues with -webkit-transform in chrome on mac

I have a page with simple transitions. I am sliding in a panel from the left (class copyDeck) and I have an element that contains an animated gif (class animatedTank) that overlays a background image. I am adding a class of loaded to the body with js onload to fire the animation.
This all works great in all browsers, a user pointed out that on a Mac with the latest version of chrome we have an issue.
The div that I slide in is actually scaling in and the animated gifs containing element slides up from the bottom (I have no animations set for this element or its parents)
h1, .copyDeck, h1 + span, div.mainContent ul{
-webkit-transform:translateX(-60%);
-moz-transform:translateX(-60%);
-o-transform:translateX(-60%);
transform:translateX(-60%);
-webkit-transition: all .5s ease-in;
-moz-transition: all .5s ease-in;
-o-transition: all .5s ease-in;
transition: all .5s ease-in;
}
.copyDeck{
-webkit-transition-delay:.125s;
-moz-transition-delay:.125s;
-o-transition-delay:.125s;
transition-delay:.125s;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
-moz-opacity: 0;
opacity:0;
margin-top: 3em;
}
.loaded h1, .loaded .copyDeck, .loaded h1 + span, .loaded div.mainContent ul, .loaded blockquote, .loaded .CTA{
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
-o-transform: translateX(0);
transform: translateX(0);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
-moz-opacity: 1;
opacity:1;
}
.animatedTank {
background: transparent url("Assets/transportation_imgSeq.gif") top left no-repeat;
width: 212px;
height: 369px;
position: relative;
top: -340px;
left: 389px;
float: left;
}
<div class="mainContent">
<div class="fadeOvr"></div>
<h1>Level Tanks</h1>
<span>& A Better Bottom Line</span>
<div class="copyDeck">
<p>
...
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
</div>
</div>
<div class="animatedTank"></div>
Does anyone know of a fix, solution or has anyone experienced this issue?

Aligning drop-down css navigation bar to the right

Basically the navigation bar on my page is aligned to right hand side of the page with the logo on its left. Because of this when the drop down for the far right item appears, it drifts off the right side of the page and looks messy. Especially as it's using an aplha background.
Anyway, here is my code at the moment..
HTML:
<ul class="Nav2">
<li>
Category 1
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 2
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 3
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 4
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
<li>
Category 5
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</li>
</ul>
CSS:
ul.Nav2 {
list-style-type:none;
margin:0 auto;
padding:0;
overflow:hidden;
width:auto;
}
ul.Nav2 li {
float:right;
}
ul.Nav2 li a {
font-family:"Orator Std";
font-size:16px;
color:#000;
display:block;
width:auto;
height:20px;
line-height:20px;
border-left:1px Solid rgba(0,0,0,255);
background-color:#CCC;
text-align:center;
text-decoration:none;
opacity:0.6;
padding:0px 10px;
-webkit-transition:all 0.2s ease-in-out;
-moz-transition:all 0.2s ease-in-out;
-ms-transition:all 0.2s ease-in-out;
-o-transition:all 0.2s ease-in-out;
transition:all 0.2s ease-in-out;
}
ul.Nav2 li a:hover {
opacity:1;
}
ul.Nav2 ul {
list-style:none;
position:absolute;
left:-9999px;
text-align:right;
}
ul.Nav2 ul li {
padding-top:1px;
float:none;
}
ul.Nav2 ul a {
white-space:nowrap;
}
ul.Nav2 li:hover ul {
left:inherit;
}
ul.Nav2 li:hover a {
background:#FFF;
text-decoration:none;
}
ul.Nav2 li:hover ul a {
text-decoration:none;
}
ul.Nav2 li:hover ul li a:hover {
background:#FFF;
}
Basically this is how I WANT it to look....
Category 1 Category 2 Category 3 Category 4 Category 5
Item 1 Item 1 Item 1 Item 1 Item 1
Item 2 Item 2 Item 2 Item 2 Item 2
Rather than...
Category 1 Category 2 Category 3 Category 4 Category 5
Item 1 Item 1 Item 1 Item 1 Item 1
Item 2 Item 2 Item 2 Item 2 Item 2
(It's actually pushed to the right slightly but not centered to the parent <ul> <li>)
The width MUST be set to auto because of the huge range in widths between the text that is gunna be stored in the navigation bar. Some are about 100px and some are nearly 300px
Here's the fixed CSS. Removed and added styles are commented.
ul.Nav2 {
list-style-type:none;
margin:0 auto;
padding:0;
overflow:hidden;
width:auto;
}
ul.Nav2>li {
float:right;
}
ul.Nav2 li a {
font-family:"Orator Std";
font-size:16px;
color:#000;
display:block;
width:auto;
height:20px;
line-height:20px;
border-left:1px Solid rgba(0,0,0,255);
background-color:#CCC;
/*removed
text-align:center;
*/
text-decoration:none;
opacity:0.6;
padding:0px 10px;
;
;
;
-o-transition:all 0.2s ease-in-out;
transition:all 0.2s ease-in-out;
}
ul.Nav2 li a:hover {
opacity:1;
}
ul.Nav2 ul {
list-style:none;
position:absolute;
left:-9999px;
text-align:right;
float:right
/*added*/
display:block;
padding:0;
min-width:9.3ex;
}
ul.Nav2 ul li {
padding-top:1px;
float:none;
}
ul.Nav2 ul a {
white-space:nowrap;
}
ul.Nav2 li:hover ul {
left:inherit;
}
ul.Nav2 li:hover a {
background:#FFF;
text-decoration:none;
}
ul.Nav2 li:hover ul a {
text-decoration:none;
}
ul.Nav2 li:hover ul li a:hover {
background:#FFF;
}
EDIT: Updated CSS based on new restriction.

CSS Animations with delay for each child element

I am trying to create a cascading effect by applying an animation to each child element. I was wondering if there is a better way to do it than this:
.myClass img:nth-child(1){
-webkit-animation: myAnimation 0.9s linear forwards;
}
.myClass img:nth-child(2){
-webkit-animation: myAnimation 0.9s linear 0.1s forwards;
}
.myClass img:nth-child(3){
-webkit-animation: myAnimation 0.9s linear 0.2s forwards;
}
.myClass img:nth-child(4){
-webkit-animation: myAnimation 0.9s linear 0.3s forwards;
}
.myClass img:nth-child(5){
-webkit-animation: myAnimation 0.9s linear 0.4s forwards;
}
and so on...
So basically, I'd like to have an animation starting for each child but with a delay.
Thanks for any input!
Addition: Maybe I did not properly explain what was my concern: It's about how to do this no matter how many children I have. How to do this without having to write down the properties for every child... for example, when I don't know how many children there are going to be.
Here's a scss way to do it using a for loop.
#for $i from 1 through 10 {
.myClass img:nth-child(#{$i}n) {
animation-delay: #{$i * 0.5}s;
}
}
What you want is the animation delay property.
#keyframes FadeIn {
0% {
opacity: 0;
transform: scale(.1);
}
85% {
opacity: 1;
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
.myClass img {
float: left;
margin: 20px;
animation: FadeIn 1s linear;
animation-fill-mode: both;
}
.myClass img:nth-child(1) { animation-delay: .5s }
.myClass img:nth-child(2) { animation-delay: 1s }
.myClass img:nth-child(3) { animation-delay: 1.5s }
.myClass img:nth-child(4) { animation-delay: 2s }
<div class="myClass">
<img src="http://placehold.it/200x150" />
<img src="http://placehold.it/200x150" />
<img src="http://placehold.it/200x150" />
<img src="http://placehold.it/200x150" />
</div>
A CSS preprocessor such as Less.js or Sass can reduce the amount of repetition, but if you're working with an unknown number of child elements or need to animate a large number then JavaScript will be the best option.
In the [hopefully near] future when attr and calc are fully supported, we'll be able to accomplish this without JavaScript.
HTML:
<ul class="something">
<li data-animation-offset="1.0">asdf</li>
<li data-animation-offset="1.3">asdf</li>
<li data-animation-offset="1.1">asdf</li>
<li data-animation-offset="1.2">asdf</li>
</ul>
CSS:
.something > li
{
animation: myAnimation 1s ease calc(0.5s * attr(data-animation-offset number 1));
}
This would create an effect where each list item animates in what would appear to be random order.
You can also make use of the transition-delay property in CSS and use JS or JQuery to assign a different delay for each child element . ( Assume s to be the starting delay in seconds )
$(".myClass img").each(function(index){
$(this).css({
'transition-delay' : s*(1+index) + 's'
});
});
So, the children will have the transition delays like 1*s, 2*s, 3*s ..... and so on. Now to create the actual animation effect simply set the required transition and the children will be animated in a sequence. Works like a charm !
If you have a lot of items (for example: I have paginated table with >1000 items and wanna each row to be animated with delay when page is loads), you can use jQuery to solve this and avoid css file rising in size. Animation delay dynamically increases.
$.each($('.myClass'), function(i, el){
$(el).css({'opacity':0});
setTimeout(function(){
$(el).animate({
'opacity':1.0
}, 450);
},500 + ( i * 500 ));
});​
EDIT:
Here is the same code I adjusted to use with animate.css (install additional plugin before use https://gist.github.com/1438179 )
$.each($(".myClass"), function(i, el){
$(el).css("opacity","0");
setTimeout(function(){
$(el).animateCSS("fadeIn","400");
},500 + ( i * 500 ));
});
Where "fadeIn" is animation type, "400" - animation execute time, 500 - delay for each element on page to be animated.
Like this:
.myClass img {
-webkit-animation: myAnimation 0.9s linear forwards;
}
.myClass img:nth-child(1){
-webkit-animation-delay: 0.1s;
}
.myClass img:nth-child(2){
-webkit-animation-delay: 0.2s;
}
[...etc...]

Resources