How to make this css3 background change a smooth loop? - html

I have created a css3 background change on my div tag, but when it loops, it does not loop with the transition. It loops as if someone has just refreshed the page. Could you guys help me into making this a smooth loop, so it loops using the transition
My code is the following:
.slideshow_container{
background-color: #ccc;
position: absolute;
width: 100%;
height: 300px;
top: 160px;
left; 0;
right:0;
z-index:1;
background:#014EAA;
animation:myfirst 25s infinite;
-moz-animation:myfirst 25s infinite; /* Firefox */
-webkit-animation:myfirst 25s infinite; /* Safari and Chrome */
-o-animation:myfirst 25s infinite; /* Opera */
box-shadow: 0 4px 2px -2px gray;
}
#keyframes myfirst
{
from {background:#014EAA;}
to {background:#467EBB;}
}
#-moz-keyframes myfirst /* Firefox */
{
from {background:#014EAA;}
to {background:#467EBB;}
}
#-webkit-keyframes myfirst /* Safari and Chrome */
{
from {background:#014EAA;}
to {background:#467EBB;}
}
#-o-keyframes myfirst /* Opera */
{
from {background:#014EAA;}
to {background:#467EBB;}
}
#-webkit-keyframes myfirst /* Safari and Chrome */
{
0% {background: #014EAA;}
50% {background: #014EAA;}
50% {background: #467EBB;}
}

http://jsfiddle.net/FqF57/1/
The issue seems to be that your using hex values.
I've tried with just switching from background with color lightblue, to background navy and it works.
#keyframes myfirst
{
from {background:lightblue;}
to {background:navy;}
}
#-moz-keyframes myfirst /* Firefox */
{
from {background:lightblue;}
to {background:navy;}
}
And I've also tried with using rgb and that works as well.
http://jsfiddle.net/rF3AH/1/
#keyframes myfirst
{
from {background: rgb(100,100,180);}
to {background:rgb(200,200,250);}
}
#-moz-keyframes myfirst /* Firefox */
{
from {background: rgb(100,100,180);}
to {background:rgb(200,200,250);}
}

Related

Why is my css animation code not working in Chrome?

This code used to work fine in Google Chrome last time but now it doesn't work anymore. The bars will fill up by a solid colour animating (2 seconds) in when you scroll it in view.
Internet Explorer works fine.
Any help, please? I've tried looking around but to no avail.
.levelPM {
height: 25px; /* IE CSS Variables Fallback */
height: var(--bar-h);
width: 0px;
background: #7ae89f; /* IE CSS Variables Fallback */
background: var(--projectmanage-col);
}
.projectmanage.start {
-webkit-animation: projectmanage 2s ease-out forwards;
-moz-animation: projectmanage 2s ease-out forwards;
-o-animation: projectmanage 2s ease-out forwards;
animation: projectmanage 2s ease-out forwards;
}
#-webkit-keyframes projectmanage {
0% { width: 0px; }
100% { width: 90%; /* IE CSS Variables Fallback */ width: var(--projectmanage-perc); }
}
#-moz-keyframes projectmanage {
0% { width: 0px; }
100% { width: 90%; /* IE CSS Variables Fallback */ width: var(--projectmanage-perc); }
}
#-o-keyframes projectmanage {
0% { width: 0px; }
100% { width: 90%; /* IE CSS Variables Fallback */ width: var(--projectmanage-perc); }
}
#keyframes projectmanage {
0% { width: 0px; }
100% { width: 90%; /* IE CSS Variables Fallback */ width: var(--projectmanage-perc); }
}
Full code: https://pastebin.com/TegPh7pf
Chrome will not trigger the scroll if the page has no scroll, use "bind (wheel)" instead.
$(window).bind("wheel", function() {
console.log("asdads")
checkAnimation2();
});
Live example: https://codepen.io/dobladov/pen/aXZpNP

How to add a quick fade in and out to CSS animation

'How can I' add a quick fade in and out to a CSS animation?
.section-1 {
-webkit-animation: my-animation 1.3s infinite;
/* Safari 4+ */
-moz-animation: my-animation 1.3s infinite;
/* Fx 5+ */
-o-animation: my-animation 1.3s infinite;
/* Opera 12+ */
animation: my-animation 1.3s infinite;
/* IE 10+, Fx 29+ */
}
#-webkit-keyframes my-animation {
0%,
49% {
background-color: white;
}
50%,
100% {
background-color: #8b72da;
}
<li class="section-1"></li>
Any help would be great, cheers
I think this is what you're looking for. I increased the duration of the animation to make the fade more apparent. Basically you have to play with the percentage values in the animation, so the transition from white to the other color doesn't happen within 1% of the animation duration:
.section-flash-ul {
list-style: none;
width: 100%;
display: inline-block;
padding: 0;
margin: 0;
}
.section-flash-item {
border: 1px solid black;
width: 33.333%;
height: 10px;
display: inline-block;
padding: 0;
margin: 0;
}
.section-1 {
/* width: 50px;
height: 50px; */
-webkit-animation: NAME-YOUR-ANIMATION 2.3s infinite; /* Safari 4+ */
-moz-animation: NAME-YOUR-ANIMATION 2.3s infinite; /* Fx 5+ */
-o-animation: NAME-YOUR-ANIMATION 2.3s infinite; /* Opera 12+ */
animation: NAME-YOUR-ANIMATION 2.3s infinite; /* IE 10+, Fx 29+ */
}
#-webkit-keyframes NAME-YOUR-ANIMATION {
0%, 30% {
background-color: white;
}
50%, 80% {
background-color: #8b72da;
}
}
.section-2 {
/* width: 50px;
height: 50px; */
-webkit-animation: NAME-YOUR-ANIMATION2 2.3s infinite; /* Safari 4+ */
-moz-animation: NAME-YOUR-ANIMATION2 2.3s infinite; /* Fx 5+ */
-o-animation: NAME-YOUR-ANIMATION2 2.3s infinite; /* Opera 12+ */
animation: NAME-YOUR-ANIMATION2 2.3s infinite; /* IE 10+, Fx 29+ */
}
#-webkit-keyframes NAME-YOUR-ANIMATION2 {
0%, 30% {
background-color: white;
}
50%, 80% {
background-color: #9d89de;
}
}
.section-3 {
/* width: 50px;
height: 50px; */
-webkit-animation: NAME-YOUR-ANIMATION3 2.3s infinite; /* Safari 4+ */
-moz-animation: NAME-YOUR-ANIMATION3 2.3s infinite; /* Fx 5+ */
-o-animation: NAME-YOUR-ANIMATION3 2.3s infinite; /* Opera 12+ */
animation: NAME-YOUR-ANIMATION3 2.3s infinite; /* IE 10+, Fx 29+ */
}
#-webkit-keyframes NAME-YOUR-ANIMATION3 {
0%, 30% {
background-color: white;
}
50%, 80% {
background-color: #b5a8e0;
}
}
<ul class="section-flash-ul">
<li class="section-flash-item section-1"></li>
<li class="section-flash-item section-2"></li>
<li class="section-flash-item section-2"></li>
</ul>
<div class="quadrat">
</div>
Seems like you need three animation positions instead of two:
animation: my-animation 1.3s infinite;
#-webkit-keyframes my-animation {
0% {
background-color: white;
}
50% {
background-color: #8b72da;
}
100% {
background-color: white;
}
Notice, in your example, you had css holding the background at white from 0 to 49%, and then the solid color from 50% to 100%. If you want smoother effects, give css more time between these states to perform the transition.
.section-1 {
-webkit-animation: my-animation 1.3s infinite;
/* Safari 4+ */
-moz-animation: my-animation 1.3s infinite;
/* Fx 5+ */
-o-animation: my-animation 1.3s infinite;
/* Opera 12+ */
animation: my-animation 1.3s infinite;
/* IE 10+, Fx 29+ */
}
#-webkit-keyframes my-animation {
0% {
background-color: white;
}
50% {
background-color: #8b72da;
}
<li class="section-1"></li>
I don't know where do you find that approach of using keyframes but from 0% to 50% would be enough.

element not retaining the final value after animation [duplicate]

This question already has answers here:
Stopping a CSS3 Animation on last frame
(8 answers)
Closed 7 years ago.
Look at the css below. bottom:0 doesn't get applied at all once the animation is over
div {
width: 100%;
position: absolute;
z-index: 999;
background: black;
color: white;
padding: 10px;
font-weight: bold;
-webkit-animation: mymove 1s; /* Chrome, Safari, Opera */
animation: mymove 1s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
div:empty {
-webkit-animation: mymoveClose 1s; /* Chrome, Safari, Opera */
animation: mymoveClose 1s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymove {
from {bottom: -30px;}
to {bottom: 0px;}
}
/* Standard syntax */
#keyframes mymove {
from {bottom: -30px;}
to {bottom: 0px;}
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymoveClose {
from {bottom: 0px;}
to {bottom: -30px;}
}
/* Standard syntax */
#keyframes mymoveClose {
from {bottom: 0px;}
to {bottom: -30px;}
}
Here is the fiddle
http://jsfiddle.net/uk4gxr8c/
You need to specify an animation-fill-mode.
In this case forwards will cause the animation to end at the final value.
Per MDN
The target will retain the computed values set by the last keyframe encountered during execution. The last keyframe encountered depends on the value of animation-direction and animation-iteration-count:
setTimeout(function() {
document.getElementById('div1').innerHTML = '';
}, 3000);
div {
width: 100%;
position: absolute;
z-index: 999;
background: black;
color: white;
padding: 10px;
height: 30px;
font-weight: bold;
box-sizing: border-box;
-webkit-animation: mymoveClose 1s;
/* Chrome, Safari, Opera */
animation: mymoveClose 1s linear forwards;
}
div:empty {
-webkit-animation: mymove 1s;
/* Chrome, Safari, Opera */
animation: mymove 1s linear forwards;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymove {
from {
bottom: -30px;
}
to {
bottom: 0px;
}
}
/* Standard syntax */
#keyframes mymove {
from {
bottom: -30px;
}
to {
bottom: 0px;
}
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymoveClose {
from {
bottom: 0px;
}
to {
bottom: -30px;
}
}
/* Standard syntax */
#keyframes mymoveClose {
from {
bottom: 0px;
}
to {
bottom: -30px;
}
}
<div id="div1">linear</div>

Why doesn't animation work in chrome?

Following code implements a marquee like animation that is working just on firefox. It is not working in chrome. What could be the reason for this ? Here is the jsfiddle that will show up only in the firefox.
CSS :
/* define the animation */
#-webkit-keyframes marquee {
0% { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}
#-moz-keyframes marquee {
0% { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}
/* define your limiting container */
.marquee {
border: solid 2px;
white-space: nowrap;
overflow: hidden;
box-sizing: border-box;
}
/* this is the tray moving around your container */
.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee 15s linear infinite; /* here you select the animation */
}
/* pause the animation on mouse over */
.marquee span:hover {
animation-play-state: paused
}
HTML :
<p class="marquee">
<span>
Hey ! What's up?
</span>
</p>
Debugging in chrome highlights this :
Haven't got Chrome installed currently, but remember to prefix -webkit to all CSS3 functions for compatibility.
#-webkit-keyframes marquee {
0% { -webkit-transform: translate(0, 0); }
100% { -webkit-transform: translate(-100%, 0); }
}
EDIT: For the error you added, utilise the above.
/* this is the tray moving around your container */
.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee 15s linear infinite; /* here you select the animation */
-webkit-animation: marquee 15s linear infinite; /* here you select the animation */
}
/* pause the animation on mouse over */
.marquee span:hover {
animation-play-state: paused;
-webkit-animation-play-state: paused;
}
Try adding the -webkit- prefix to make it work in webkit browsers. Reference
/* this is the tray moving around your container */
.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
-webkit-animation: marquee 15s linear infinite; /* Chrome, Safari, Opera */
animation: marquee 15s linear infinite; /* here you select the animation */
}
/* pause the animation on mouse over */
.marquee span:hover {
-webkit-animation-play-state: paused /* Chrome, Safari, Opera */
animation-play-state: paused
}
As pointed out by James Hunt, you might need to prefix the "transform" attribute with -webkit- aswell.
in the "marque span" css definition, add the -webkit- prefix to the animation attribute do it will work in chrome and safari

Animation on load delay, without showing

I want to fade in my logo at page load. But, I want it to delay. But when I add the delay property, it first shows, and after the delay period it starts the animation. I want the logo to show, after the delay. What am I doing wrong?
Here's the JSFiddle http://jsfiddle.net/c8hx9/
HTML
<div id="show">hello!</div>
CSS
#show {
position: absolute;
left: 50%;
margin-left: -200px;
top: 200px;
margin-bottom: 300px;
animation: fadein 2s;
-moz-animation: fadein 2s;
/* Firefox */
-webkit-animation: fadein 2s;
/* Safari and Chrome */
-o-animation: fadein 2s;
/* Opera */
animation-delay:1s;
-webkit-animation-delay:1s;
}
#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;
}
}
Just add opacity on the first statement class:
#show {
opacity:0;
}
And to keep the final of the animation use forwards.
animation-fill-mode: forwards;
Check this Demo http://jsfiddle.net/c8hx9/2/