css animation not triggering after media query - html

i have a list that looks like this
<ul class="timeline-container">
<li class="timeline-item-container">
<div class="timeline-item></div>
</li>
<li class="timeline-item-container">
<div class="timeline-item></div>
</li>
</ul>
I declare the 2 animations
#keyframes slideLeft
{
from {
transform: translateX(1000px);
}
to {
transform: translateX(0);
}
}
#keyframes slideRight
{
from {
transform: translateX(-1000px);
}
to {
transform: translateX(0);
}
}
Then on my css i have this:
.timeline-item
{
animation: slideRight .6s ease both;
#media (max-width:767px)
{
animation: slideLeft .6s ease both;
}
}
So this works perfect, all the items in my list slide in from the right when the screen is smaller than 767px and from the left when its any bigger. when i resize the screen, the animation plays again.
Now i want every odd item in the list to slide in from the right when the screen is bigger than 767px so I add this:
.timeline-item-container:nth-child(even) .timeline-item
{
#media (min-width:767px)
{
animation: slideLeft .6s ease both;
}
}
This works if i refresh the page but if i resize the screen, the animation doesnt play. It should play the animation when the screen resizes like before
I know the animation is there because if i refresh it, it plays, just not after i resize the screen
Any help is appriciated
https://jsfiddle.net/7pk6yncd/

I think the only way is to define the same animation twice under different names. Actually the animation you are using is the same so the media query will not trigger it again.
.box {
background:red;
animation:fromLeft 2s linear forwards;
}
#media all and (max-width:600px) {
.box {
background:blue;
display:block;
animation:fromLeft-alt 2s linear forwards;
}
}
#keyframes fromLeft {
from {
transform:translateX(-100%);
}
}
#keyframes fromLeft-alt {
from {
transform:translateX(-100%);
}
}
<div class="box">
some content
</div>

You can not place #media in css rule.
It works the other way, here you go:
.timeline-item
{
animation: slideRight .6s ease both;
}
#keyframes slideLeft
{
from {
transform: translateX(1000px);
}
to {
transform: translateX(0);
}
}
#keyframes slideRight
{
from {
transform: translateX(-1000px);
}
to {
transform: translateX(0);
}
}
#media (max-width:767px)
{
.timeline-item{
animation: slideLeft .6s ease both;
}
.timeline-item-container:nth-child(even) .timeline-item
{
animation: slideRight .6s ease both;
}
}

Related

CSS Animation doesn't play

I have been trying to do a simple animation in CSS. The app logo is supposed to move 200px to the right and then return, smoothly, to it's original position. To do this I have written this for the animations:
/* LOGO MAIN STYLE */
.App-logo {
height: 40vmin;
pointer-events: none;
}
/* ANIMATION FOR THE LOGO */
.App-logo {
animation-fill-mode: forwards, none;
animation-name: move-right, move-left;
animation-delay: 0s, 1s;
animation-duration: 1s, 1s;
animation-iteration-count: infinite, infinite;
animation-timing-function: ease-in-out, ease-in-out;
}
#keyframes move-right {
from {
transform: translateX(0%);
}
to {
transform: translateX(200px);
}
}
#keyframes move-left {
from {
transform: translateX(0%);
}
to {
transform: translateX(-200px);
}
}
The problem I am having is that the first animation never actually plays, it just skips to the second.
/* LOGO MAIN STYLE */
.App-logo {
height: 40vmin;
pointer-events: none;
}
/* ANIMATION FOR THE LOGO */
.App-logo {
animation-name: move-right;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
}
#keyframes move-right {
0%{
transform: translateX(0%);
}
50% {
transform: translateX(200px);
}
100% {
transform: translateX(0px);
}
}
/* LOGO MAIN STYLE */
.App-logo {
height: 40vmin;
pointer-events: none;
}
/* ANIMATION FOR THE LOGO */
.App-logo {
animation-name: move-right;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
}
#keyframes move-right {
0%{
transform: translateX(0%);
}
50% {
transform: translateX(200px);
}
100% {
transform: translateX(0px);
}
}

Delay item hover by 1 second using webkit-animation CSS

I have tried multiple ways to delay the hover of a dropdown menu item by 1 second.
transition-delay:1s; does not work. I was advised to do this through a webkit-animation with a 1s.
Here is my CSS:
#media screen and (min-width: 769px) {
.bss-megamenu-fw .dropdown-menu {
-webkit-animation: 0.1s linear 1s normal forwards 1 fadein;
}
}
#keyframes fadein{
0% { opacity:0; }
66% { opacity:0; }
83% { opacity:1; }
100% { opacity:1; }
}
#-webkit-keyframes fadein{
0% { opacity:0; }
66% { opacity:0; }
83% { opacity:1; }
100% { opacity:1; }
}
I am at a loss because this doesn't work. How can I get my delay?
I fixed it by adding the following to the .bss-megamenu-fw .dropdown-menu class:
animation: 0.1s linear 0.5s normal forwards 1 fadein;

Defining animation direction when using multiple animations on same element

I have this:
.about5 {
animation: fade 4s ease forwards, warp 1s linear;
animation-delay: 2s;
}
#keyframes rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(95deg);
}
}
#keyframes fade {
0% {
opacity: 1;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes warp {
50% {
transform: translateZ(-10px) rotateX(60deg) rotateZ(29deg) rotateY(-180deg);
}
}
<div class="about5">About</div>
<div class="about">About text etc</div>
Why, when I have separated multiple animations by a comma, will the second animation:
#keyframes warp {
50% {
transform: translateZ(-10px) rotateX(60deg)
rotateZ(29deg) rotateY(-180deg);
}
}
#media (min-width: 768px) {.about {
animation:
spin 20s linear infinite, warp 2s linear infinite; animation.
delay: 4s;}}
not take effect?
I want aboutelement to spin and translateZ but it's not working. Is this because of the comma in the wrong place?
It works ok, your problem must be in another place:
.about5 {
animation: fade 16s ease forwards infinite, warp 4s linear infinite;
animation-delay: 2s;
}
#keyframes fade {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes warp {
50% {
transform: translateZ(-10px) rotateX(60deg) rotateZ(29deg) rotateY(-180deg);
}
<div class="about5">About</div>
<div class="about">About text etc</div>

Slide in from left CSS animation

I would like to make a simple animation, when the page loads, my logo should animate from the left side of the box to the right side. I have tried many versions, but haven't succeeded yet.
HTML
<body>
<div>
<img src="logo.png" alt="logo" style="width:170px;height:120px;">
</div>
</body>
CSS
div
{
width:640px;
height:175px;
background:blue;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
position:absolute;
}
div img
{
-webkit-transform: translate(3em,0);
-moz-transform: translate(3em,0);
-o-transform: translate(3em,0);
-ms-transform: translate(3em,0);
}
Try using keyframes.
div {
width: 50px;
height: 40px;
background: blue;
position: relative;
left: 500px;
-webkit-animation: slideIn 2s forwards;
-moz-animation: slideIn 2s forwards;
animation: slideIn 2s forwards;
}
#-webkit-keyframes slideIn {
0% {
transform: translateX(-900px);
}
100% {
transform: translateX(0);
}
}
#-moz-keyframes slideIn {
0% {
transform: translateX(-900px);
}
100% {
transform: translateX(0);
}
}
#keyframes slideIn {
0% {
transform: translateX(-900px);
}
100% {
transform: translateX(0);
}
}
<div></div>
You need to use animation instead of transition. Transition effects are triggered on certain events, for example a click which adds a class or a hover.
div img {
animation: example 1s ease-in-out forwards;
}
#keyframes example {
from {transform: transition(0,0)}
to {transform: transition(3em,0)}
}
Now you would of course have to add the prefixes for that, webkit, moz, etc.
For basic knowledge about keyframe animation in css3:
http://www.w3schools.com/css/css3_animations.asp

Keep div faded out after transition

I am using a css code to fade in and then fade out an html div, and after a delay, fade in another div. However, after the second div fades in and the code ends, the first div reappears. The code I am using is posted below. I wanted to know how to make sure the first div dosent reappear after the code ends.
.text {
-webkit-animation: fadein 5s
}
#-webkit-keyframes fadein {
0% {
opacity: 0;
}
35% {
opacity: 1;
}
72% {
opacity:1;
}
100% {
opacity:0;
}
}
#-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
#-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
#keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.bdy {
opacity:0; /* make things invisible upon start */
-webkit-animation:fadeIn ease-in 1; /* call our keyframe named fadeIn, use animattion ease-in and repeat it only 1 time */
-moz-animation:fadeIn ease-in 1;
animation:fadeIn ease-in 1;
-webkit-animation-fill-mode:forwards; /* this makes sure that after animation is done we remain at the last keyframe value (opacity: 1)*/
-moz-animation-fill-mode:forwards;
animation-fill-mode:forwards;
-webkit-animation-duration:1s;
-moz-animation-duration:1s;
animation-duration:1s;
}
.bdy {
-webkit-animation-delay: 4.5s;
-moz-animation-delay: 4.5s;
animation-delay: 4.5s;
}
HTML:
<header>
<div class="text_paragraph">
<h1>DEMO</h1>
<h3>Secondary School</h3>
<h3>Grade</h3>
</div>
<div class="bdy">
<h1>hi</h1>
</div>
</header>
You can do something like this ... here is a jsFiddle
Obs: Add the other css selectors besides -webkit- to make it cross-browser
CSS
.text_paragraph {
-webkit-animation: fadeInOut 2s;
opacity:0;
}
.bdy {
-webkit-animation:fadeIn 3s;
}
#-webkit-keyframes fadeInOut{
0% {
opacity: 0;
}
35% {
opacity: 1;
}
72% {
opacity:1;
}
100% {
opacity:0;
}
}
#-webkit-keyframes fadeIn{
0% {
opacity: 0;
}
75% {
opacity:0;
}
100% {
opacity:1;
}
}