So am fairly new in CSS animation and I wanted to ask a question I created this box and it as a small box inside that rotates from top to bottom, right to left and alternate but am wondering how can I make that it rotates fully around continuously, from the point of origin.
I tried setting the transform translateX to -232% once it reach back at the point of origin but end up not going back to its origin as intent.
<div class="parent">
<div class="child"></div>
</div>
<style>
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font-size: 62.5%;
font-family: Arial, Helvetica, sans-serif;
}
body {
font-size: 1.22rem;
line-height: 1.2;
}
.parent {
background: #aed4ff;
height: 300px;
width: 300px;
}
.child {
background-color: rgb(143, 36, 36);
width: 90px;
height: 90px;
display: block;
}
.parent:hover .child {
animation: left-to-right 2s ease-in-out forwards;
animation-play-state: paused;
cursor: pointer;
}
#keyframes left-to-right {
0% {
transform: translateX(0);
color: red;
}
33% {
transform: translateY(232%);
}
50% {
background-color: blue;
}
66% {
transform: translateX(232%) translateY(232%);
}
100% {
transform: translateX(232%);
background-color: black;
}
}
</style>
You need to add another keyframe with translateX(0) at 100% to move the element back to the original position, and for the other "transform-keyframes" use 25%, 50% and 75% instead of 33%, 67% and 100%.
And of course animation-iteration-count: infinite; to keep it going round.
So that would be
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font-size: 62.5%;
font-family: Arial, Helvetica, sans-serif;
}
body {
font-size: 1.22rem;
line-height: 1.2;
}
.parent {
background: #aed4ff;
height: 300px;
width: 300px;
}
.child {
background-color: rgb(143, 36, 36);
width: 90px;
height: 90px;
display: block;
}
.parent:hover .child {
animation: left-to-right 3s ease-in-out forwards;
animation-iteration-count: infinite;
cursor: pointer;
}
#keyframes left-to-right {
0% {
transform: translateX(0);
color: red;
}
25% {
transform: translateY(232%);
}
50% {
transform: translateX(232%) translateY(232%);
background-color: blue;
}
75% {
transform: translateX(232%);
}
100% {
transform: translateX(0);
background-color: black;
}
}
<div class="parent">
<div class="child"></div>
</div>
You can set your animation to run continuously by adding this to your css
animation-iteration-count: infinite;
Related
I am currently working on an intro transition. Where the following should happen:
A Background-Color transition from a set of different background colors
A word swapping transition -> here should each word change with a fade in and out + blur transition
The basics are working pretty good here, but I can’t get my head around that the whole transition working simultaneously.
Especially the blur in and out transition isn't totally out of timing. I tried so many different values.
My Code:
(function(){
var words = ['Fade', 'Blur', 'Word'], i = 0;
setInterval(function(){
$('#swap-text').fadeOut(1250, function(){
$(this).html(words[i=(i+1)%words.length]).fadeIn(1250, "linear");
});
},3000);
})();
body{
font-family: sans-serif;
font-weight:100;
padding:0;
margin: 0;
}
#keyframes colorfont {
0% { color: #C0FF01; }
33% { color: #013334; }
66% { color: #C0FF01; }
100% { color: #C0FF01; }
}
#keyframes glow {
0% { background: #013334; }
33% { background: #C0FF01; }
66% { background: #8E7DD2; }
100% { background: #C0FF01; }
}
.intro-claim{
opacity: 1;
}
.intro-content{
width: 100vw;
height: 100vh;
display: flex;
position: relative;
align-items: center;
justify-content: center;
z-index: 0;
}
.intro-content p {
max-width: 1215px;
padding: 0 50px;
color: #C0FF01;
// opacity: 0;
text-align: left;
font-size: 45px;
line-height: 1.2;
animation: colorfont 9s infinite;
animation-delay: 3s;
animation-timing-function: linear;
}
.intro-background{
width: 100%;
z-index: -100;
height: 100vh;
display: flex;
position: fixed;
top:0;
background: #013334;
animation: glow 9s infinite;
animation-delay: 3s;
}
#swap-text{
margin-left: 12px;
font-weight:800;
animation: blur 4250ms linear 0s infinite normal none;
animation-delay: 3s;
}
#keyframes blur {
0%{
-webkit-filter: blur(0px);
}
20%{
-webkit-filter: blur(0px);
}
40%{
-webkit-filter: blur(8px);
}
60%{
-webkit-filter: blur(8px);
}
80%{
-webkit-filter: blur(0px);
}
100%{
-webkit-filter: blur(0px);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header class="intro-content">
<div class="intro-logo intro-claim">
<p>life is full of impressions. some of them remain. we create contemporary experiences, that people love to<span id="swap-text">Fade</span></p>
</div>
</header>
<div class="intro-background"></div>
Codepen:
https://codepen.io/Dennisade/pen/eYGBPjq
I think it is just a matter of having 4 different pendulums (animations) with varying time periods and balancing them. So I have made some changes to the time periods in your codepen, specifically css and js, see if this works for you.
CSS:
$transition: 500ms cubic-bezier(0.485, 0.355, 0.345, 0.950);
$green: #013334;
$lightblue: #E3EAF4;
$brightmood: #8E7DD2;
$yellow: #C0FF01;
$introvalue: 9s;
$introdelay: 3s;
body{
font-family: sans-serif;
font-weight:100;
padding:0;
margin: 0;
}
#keyframes colorfont {
0% { color: $yellow; }
33% { color: $green; }
66% { color: $yellow; }
100% { color: $yellow; }
}
#keyframes glow {
0% { background: $green; }
33% { background: $yellow; }
66% { background: $brightmood; }
100% { background: $green; }
}
.intro-claim{
opacity: 1;
}
.intro-content{
width: 100vw;
height: 100vh;
display: flex;
position: relative;
align-items: center;
justify-content: center;
z-index: 0;
p {
max-width: 1215px;
padding: 0 50px;
color: $yellow;
// opacity: 0;
text-align: left;
font-size: 45px;
line-height: 1.2;
animation: colorfont $introvalue infinite;
animation-delay: $introdelay;
animation-duration: 6s;
}
}
.intro-background{
width: 100%;
z-index: -100;
height: 100vh;
display: flex;
position: fixed;
top:0;
background: $green;
animation: glow $introvalue infinite;
animation-duration: 6s;
animation-delay: $introdelay;
}
#swap-text{
margin-left: 12px;
font-weight:800;
animation: blur 4250ms infinite;
animation-delay: $introdelay;
animation-duration: 2s;
}
#keyframes blur {
0%{
-webkit-filter: blur(0px);
}
50%{
-webkit-filter: blur(8px);
}
100%{
-webkit-filter: blur(0px);
}
}
JS:
(function(){
var words = ['Fade', 'Blur', 'Word'], i = 0;
setInterval(function(){
$('#swap-text').fadeOut(500, function(){
$(this).html(words[i=(i+1)%words.length]).fadeIn(500, "linear");
});
},2000);
})();
https://codepen.io/gamezordd/pen/oNGYQwp
I'm trying to animate the second part of the sentence to change words. div box is the non-changing part, and div word is the changing part. Even though in every guide I've read, it says defining position as absolute and hiding overflow will fix the starting position of second part of the sentence, it still keeps changing. Here's my CSS:
body
{
margin: 0;
padding: 0;
background: #B4B8AB;
}
.box
{
position: absolute;
top: 50%;
transform: translateY(-50%);
font-size: 3em;
font-family: arial;
color: #fff;
margin-left: 150px;
width: calc(100% - 50px)
text-shadow: 0 2px 2px rgba(0,0,0,.5);
}
.word
{
display: inline-block;
color: #e65c00;
}
.word span
{
position: aboslute;
top: 0;
overflow: hidden;
animation: animate 12s linear infinite 0s;
opacity: 0;
}
#keyframes animate
{
0%
{
opacity: 0;
transform: translateY(-50px);
}
2%
{
opacity: 1;
transform: translateY(0px);
}
15%
{
opacity: 1;
transform: translateY(0px);
}
20%
{
opacity: 0;
transform: translateY(50px);
}
80%
{
opacity: 0;
transform: translateY(50px);
}
100%
{
opacity: 0;
transform: translateY(50px);
}
}
.word span:nth-child(1)
{
animation-delay: 0s;
}
.word span:nth-child(2)
{
animation-delay: 2s;
}
.word span:nth-child(3)
{
animation-delay: 4s;
}
.word span:nth-child(4)
{
animation-delay: 6s;
}
.word span:nth-child(5)
{
animation-delay: 8s;
}
.word span:nth-child(6)
{
animation-delay: 10s;
}
HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Tickets</title>
<link rel="stylesheet" href="homepage.css">
</head>
<body>
<div id="menu">
<div class="logo">
<nav>
<img src="../images/mylogo.png" height="30" width="156" />
</nav>
</div>
</div>
<div class="box">
Sick of
<div class="word">
<span>wasting your time and money?</span>
<span>unreliable Ubers?</span>
<span>being stuck in traffic?</span>
<span>waiting in line?</span>
<span>sold out tickets?</span>
<span>logistical nightmares?</span>
</div>
</div>
</body>
</html>
Found the error on line 26 in the CSS
position: aboslute;
Change it to absolute and you are good to go ;)
Fiddle example here
Also, very cool effect!
New request
Figured it out. There was a missing ;
.box
{
position: absolute;
top: 50%;
transform: translateY(-50%);
font-size: 3em;
font-family: arial;
color: #fff;
margin-left: 150px;
width: calc(100% - 50px); /* <--- Right here */
text-shadow: 0px 2px 2px rgba(0,0,0,.5);
}
New Fiddle example here
I use CSS Pie Timer, and I struggle to make my pie loading animation run only once.
The order I want the animation to be in:
the circle is not shown
the circle is starting to fill up with a border color
the circle get filled fully
the circle stays filled (and doesn't repeat)
Demo here
<div class="wrapper">
<div class="pie spinner"></div>
<div class="pie filler"></div>
<div class="mask"></div>
</div>
Help will be appreciated!
You just have to remove animation-iteration-count - infinite and add animation-fill-mode as forwards.
Here is the working code
.wrapper {
position: relative;
margin: 40px auto;
background: white;
}
.wrapper, .wrapper * {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.wrapper {
width: 250px;
height: 250px;
}
.wrapper .pie {
width: 50%;
height: 100%;
transform-origin: 100% 50%;
position: absolute;
background: #08C;
border: 5px solid rgba(0,0,0,0.5);
}
.wrapper .spinner {
border-radius: 100% 0 0 100% / 50% 0 0 50%;
z-index: 200;
border-right: none;
animation: rota 5s linear forwards;
}
.wrapper:hover .spinner,
.wrapper:hover .filler,
.wrapper:hover .mask {
animation-play-state: running;
}
.wrapper .filler {
border-radius: 0 100% 100% 0 / 0 50% 50% 0;
left: 50%;
opacity: 0;
z-index: 100;
animation: opa 5s steps(1, end) forwards reverse;
border-left: none;
}
.wrapper .mask {
width: 50%;
height: 100%;
position: absolute;
background: inherit;
opacity: 1;
z-index: 300;
animation: opa 5s steps(1, end) forwards;
}
#keyframes rota {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#keyframes opa {
0% {
opacity: 1;
}
50%, 100% {
opacity: 0;
}
}
<div class="wrapper">
<div class="pie spinner"></div>
<div class="pie filler"></div>
<div class="mask"></div>
</div>
I'm trying to make a responsive "listening" loader but I'm having some issues trying to center all 3 elements.
See the "clean" JSFiddle here: http://jsfiddle.net/mfaeqxn9/ (the mic, needs to be in the center of the loader).
This is the CSS:
body{
background: #151515
}
#listenericon{
color:#23d05f;
font-size:82px;
}
.circle {
background-color: rgba(0,0,0,0);
border: 20px solid rgba(35,208,95,0.9);
opacity: .9;
border-right: 20px solid rgba(0,0,0,0);
border-left: 20px solid rgba(0,0,0,0);
border-radius: 999px;
width: 200px;
height: 200px;
margin: 0 auto;
-moz-animation: spinPulse 1s infinite ease-in-out;
-webkit-animation: spinPulse 1s infinite linear;
}
.circle1 {
background-color: rgba(0,0,0,0);
border: 20px solid rgba(35,208,95,0.9);
opacity: .9;
border-left: 20px solid rgba(0,0,0,0);
border-right: 20px solid rgba(0,0,0,0);
border-radius: 999px;
width: 120px;
height: 120px;
margin: 0 auto;
position: relative;
top: -288px;
-moz-animation: spinoffPulse 1s infinite linear;
-webkit-animation: spinoffPulse 1s infinite linear;
}
#-moz-keyframes spinPulse {
0% {
-moz-transform: rotate(160deg);
opacity: 0;
box-shadow: 0 0 1px #23d05f;
}
50% {
-moz-transform: rotate(145deg);
opacity: 1;
}
100% {
-moz-transform: rotate(-320deg);
opacity: 0;
};
}
#-moz-keyframes spinoffPulse {
0% {
-moz-transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
};
}
#-webkit-keyframes spinPulse {
0% {
-webkit-transform: rotate(160deg);
opacity: 0;
box-shadow: 0 0 1px #23d05f;
}
50% {
-webkit-transform: rotate(145deg);
opacity: 1;
}
100% {
-webkit-transform: rotate(-320deg);
opacity: 0;
};
}
#-webkit-keyframes spinoffPulse {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
};
}
#import url(https://fonts.googleapis.com/icon?family=Material+Icons);
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
width: 1em;
height: 1em;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
I've tried the translate 50% version and many others, but since it needs to be responsive I have yet to find a proper solution. I'm fine with flexbox, but so far I havent figured out how to make the divs overlap each other.
Anyone have a good solution for this?
Here's the solution (I have updated the codes as your requirement):
Working demo
#listenericon{
color:#23d05f;
font-size:82px;
margin-top:10px;
width:120px;
display: block;
position: relative;
margin: 0 auto;
padding-top: 78px; }
.mic{
position: absolute;
top: 0;
left: 0;
width:100%; }
Fully Responsive Check Running Code, Two Main Issues : Use Position Absolute if you want to overlap two divs , and control that divs using position relative , check : Fiddle Code
<div class="loader">
<div class="circle"></div>
<div class="circle1"><i id="listenericon" class="material-icons">mic</i></div>
#listenericon{
color:#23d05f;
font-size:82px; margin:10px 0 0 0;
}
.loader{position:relative; float:left; width:100%; height:270px;}
My goal is to create a dropdown that fades in every time its parent element is moused over.
And, I want to use the CSS #keyframe property to control the opacity.
See the below example. It works in IE and Chrome as expected (fade-in happens on every mouse over). But, in FireFox, the fade-in happens only on the first mouse over. How can I get the fade-in to happen every time in FireFox?
CodePen showing example:
http://codepen.io/anon/pen/IEBgb
(notice the green "Baz" text fades in)
HTML:
<div class="foo">Foo
<div class="bar">
<div class="baz">
Baz
</div>
</div>
</div>
CSS:
#-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;
}
}
.foo {
cursor: pointer;
background: #333;
color: #ededed;
height: 50px;
line-height: 50px;
position: relative;
text-align: center;
width: 200px;
font-size: 30px;
}
.bar {
width: 200px;
position: absolute;
top: 52px;
background: gray;
display: none;
padding: 20px 0;
}
.foo:hover .bar {
display: block;
}
.baz {
font-size: 50px;
color: green;
visibility: visible;
opacity: 1;
-webkit-animation: fadeIn 2s;
-moz-animation: fadeIn 2s;
-o-animation: fadeIn 2s;
animation: fadeIn 2s;
}
It can be done, but you will have to adjust a few things:
Working Example
#-webkit-keyframes fadeIn {
0% {
color: rgba(0, 128, 0, 0); /* transparent text color */
opacity: 0;
}
50% {
color: rgba(0, 128, 0, 0); /* transparent text color */
opacity:1;
}
100% {
color: rgba(0, 128, 0, 1); /* fade in text color */
opacity: 1;
}
}
#keyframes fadeIn {
0% {
color: rgba(0, 128, 0, 0);
opacity: 0;
}
50% {
color: rgba(0, 128, 0, 0);
opacity:1;
}
100% {
color: rgba(0, 128, 0, 1);
opacity: 1;
}
}
.foo {
cursor: pointer;
background: #333;
color: #ededed;
height: 50px;
line-height: 50px;
position: relative;
text-align: center;
width: 200px;
font-size: 30px;
}
.bar {
display:none;
width: 200px;
position: absolute;
top: 50px;
background: gray;
padding: 20px 0;
}
.baz {
font-size: 50px;
}
.foo:hover .bar {
display: block;
-webkit-animation: fadeIn 2s both; /* attach the animation to bar rather than baz */
animation: fadeIn 2s both;
}
Or if you're looking to fade in and fade out you could try something like this:
Working Example 2
Note that the second method uses pointer-events:none/auto so it may have compatibility issues in older browsers. Also seeing the fadeOut animation when the page first loads may be a problem.