I have created an container that if filling up and I want to apply to that some "waves animated effect" and I'm a bit stuck because I am not sure how to do it:
Does anyone cand help me with those waves effecct animations ?
body {
background-color: #015871;
}
.container {
position: relative;
width: 700px;
height: 300px;
margin: 100px auto;
}
.shape {
width: 200px;
height: 200px;
border-radius: 50%;
border-top-right-radius: 0;
transform: rotate(-45deg);
float: left;
margin-top: 50px;
margin-left: 20px;
border: 5px solid #fff;
overflow: hidden;
position: relative;
}
.frame {
position: absolute;
transform: rotate(225deg);
background-color: #00eaff;
bottom: -80px;
left: -80px;
right: 0;
height: 10px;
width: 200%;
animation: fill-up 1s ease infinite;
}
#keyframes fill-up {
to {
height: 300px;
}
}
<div class="container">
<div class="shape">
<div class="frame" />
</div>
</div>
working example: https://codesandbox.io/s/vigorous-keldysh-uw2po?file=/src/styles.css:81-720
Improved your code with inner element .wave with two rotating blocks. No JavaScript, no svg. Switch overflow hidden off to see how simple it works.
body {
background-color: #015871;
}
.container {
position: relative;
width: 700px;
height: 300px;
margin: 100px auto;
}
.shape {
width: 200px;
height: 200px;
border-radius: 50%;
border-top-right-radius: 0;
transform: rotate(-45deg);
float: left;
margin-top: 50px;
margin-left: 20px;
border: 5px solid #fff;
overflow: hidden;
position: relative;
}
.frame {
position: absolute;
transform: rotate(45deg);
background-color: rgba(0, 234, 255, 0.5);
bottom: -8px;
left: 15px;
right: 0;
height: 245px;
width: 200px;
}
.wave {
position: absolute;
top: 50%;
left: 0;
width: 200%;
height: 200%;
transform: translate(-25%, 0);
background: #4973ff;
animation: fill-up 10s ease infinite;
}
#keyframes fill-up {
to {
top: -60%;
}
}
.wave:before,
.wave:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 50%;
transform: translate(-50%, -75%);
background: #000;
}
.wave:before {
border-radius: 45%;
background: rgba(1, 88, 113, 1);
animation: animate 3s linear infinite;
}
.wave:after {
border-radius: 40%;
background: rgba(1, 88, 113, 0.5);
animation: animate 3s linear infinite;
}
#keyframes animate {
0% {
transform: translate(-50%, -75%) rotate(0deg);
}
100% {
transform: translate(-50%, -75%) rotate(360deg);
}
}
<div class="container">
<div class="shape">
<div class="frame">
<div class="wave">
</div>
</div>
</div>
</div>
Working example https://codepen.io/focus-style/pen/oNbxVBX
Related
I've created two animations with CSS a clock and a bouncing ball. Separately they both work as intended, but once I put them in the same file the bouncing ball disappeared.
If I delete #keyframes rotation the clock stops working but the bouncing ball appears. Is there any way how to make both animations work?
.clock {
position: relative;
width: 400px;
height: 400px;
border: 10px solid;
border-radius: 50%;
}
#second {
position: absolute;
background: black;
width: 2px;
height: 180px;
margin: 20px 199px;
animation: rotation 60s infinite linear;
transform-origin: bottom left;
}
#minute {
position: absolute;
background: black;
width: 6px;
height: 140px;
margin: 60px 197px;
animation: rotation 3600s infinite linear;
transform-origin: bottom right;
}
#hour {
position: absolute;
background: black;
width: 10px;
height: 120px;
margin: 80px 195px;
animation: rotation 43200s infinite linear;
transform-origin: bottom left;
}
#keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
.box {
position: relative;
}
.ball {
position: absolute;
height: 100px;
width: 100px;
border: 3px solid pink;
border-radius: 50%;
animation: bounce 2s infinite;
background: pink;
}
.step1 {
position: absolute;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
.step2 {
position: absolute;
top: 150px;
left: 220px;
margin-top: 20px;
height: 10px;
width: 220px;
background: cyan;
}
.step3 {
margin-top: 40px;
position: absolute;
left: 440px;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
#keyframes bounce {
from {margin: 100pxz 0px;}
to{margin: 50px 500px;}
0% {
transform: translateY(-30%);
}
12% {
transform: translateY(33%);
}
24% {
transform: translateY(-66%);
}
36% {
transform: translateY(33%);
}
48% {
transform: translateY(-20%);
}
100% {
transform: translateY(33%);
}
<div class="clock">
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
</div>
<div class="box">
<div class="step1"></div>
<div class="step2"></div>
<div class="step3"></div>
<div class="ball"></div>
</div>
It works fine, you're/were missing the closing brackets on your keyframes
.clock {
position: relative;
width: 400px;
height: 400px;
border: 10px solid;
border-radius: 50%;
}
#second {
position: absolute;
background: black;
width: 2px;
height: 180px;
margin: 20px 199px;
animation: rotation 60s infinite linear;
transform-origin: bottom left;
}
#minute {
position: absolute;
background: black;
width: 6px;
height: 140px;
margin: 60px 197px;
animation: rotation 3600s infinite linear;
transform-origin: bottom right;
}
#hour {
position: absolute;
background: black;
width: 10px;
height: 120px;
margin: 80px 195px;
animation: rotation 43200s infinite linear;
transform-origin: bottom left;
}
#keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
.box {
position: relative;
}
.ball {
position: absolute;
height: 100px;
width: 100px;
border: 3px solid pink;
border-radius: 50%;
animation: bounce 2s infinite;
background: pink;
}
.step1 {
position: absolute;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
.step2 {
position: absolute;
top: 150px;
left: 220px;
margin-top: 20px;
height: 10px;
width: 220px;
background: cyan;
}
.step3 {
margin-top: 40px;
position: absolute;
left: 440px;
top: 150px;
height: 10px;
width: 220px;
background: cyan;
}
#keyframes bounce {
from {
margin: 100pxz 0px;
}
to {
margin: 50px 500px;
}
0% {
transform: translateY(-30%);
}
12% {
transform: translateY(33%);
}
24% {
transform: translateY(-66%);
}
36% {
transform: translateY(33%);
}
48% {
transform: translateY(-20%);
}
100% {
transform: translateY(33%);
}
}
<div class="clock">
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
</div>
<div class="box">
<div class="step1"></div>
<div class="step2"></div>
<div class="step3"></div>
<div class="ball"></div>
</div>
How do I make the blue platform look like its going to the left, reappears on the right and continues going left? To me, It's kind of tricky because it starts from the left, if it starts from the right than that would be easier.
*{
padding: 0;
margin: 0;
}
html,body{
height:100%;
}
.container{
height: 100%;
display: flex;
justify-content: center;
align-items: center;
align-content: center;
}
#inner{
width: 500px;
height: 200px;
border: 1px solid black;
margin: auto;
overflow:hidden
}
#platform{
width:200px;
height:50px;
position: relative;
top: 150px;
background: blue;
animation: move 2s linear infinite;
}
#keyframes move{
0%{
left:0px;
}
50%{
left:-200px;
}
70%{
right:200px;
}
100%{
left:0%
}
<div class="container">
<div id="inner">
<div id="platform"></div>
</div>
</div>
Do it like below:
#inner {
width: 500px;
height: 200px;
border: 1px solid black;
margin: auto;
overflow: hidden
}
#platform {
width: 200px;
height: 50px;
position: relative;
top: 150px;
right: 0;
transform: translate(100%);
margin-left: auto;
background: blue;
animation: move 2s linear infinite;
}
#keyframes move {
to {
right: 100%;
transform: translate(0);
}
}
<div id="inner">
<div id="platform"></div>
</div>
Control the delay to start from the left:
#inner {
width: 500px;
height: 200px;
border: 1px solid black;
margin: auto;
overflow: hidden
}
#platform {
width: 200px;
height: 50px;
position: relative;
top: 150px;
right: 0;
transform: translate(100%);
margin-left: auto;
background: blue;
animation: move 2s linear infinite -1.5s;
}
#keyframes move {
to {
right: 100%;
transform: translate(0);
}
}
<div id="inner">
<div id="platform"></div>
</div>
This is pretty crude, but you get the idea:
https://codepen.io/seanstopnik/pen/164585fcf077f8cefaef6d0f4fbd9dad
body {
padding: 60px;
}
.container {
position: relative;
width: 400px;
height: 400px;
border: 1px solid #333;
overflow: hidden;
}
.box {
position: absolute;
top: 0;
left: -100px;
height: 60px;
width: 100px;
background: blue;
-webkit-animation: box 2s linear infinite;
animation: box 2s linear infinite;
}
#-webkit-keyframes box {
0% {
transform: translateX(500px);
}
}
#keyframes box {
0% {
transform: translateX(500px);
}
}
<div class="container">
<div class="box"></div>
</div>
My animation works but after one turn, the square rotate of 45 deg,
I don't understand why.
https://codepen.io/igamanstudio/pen/ZPYWWO
.card {
/* Add shadows to create the "card" effect */
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 300px;
height: 300px;
margin: 150px auto;
}
.anim-square {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: spin 20s linear infinite;
}
.losange-wrap {
position: relative;
}
.losange-1 {
position: absolute;
overflow: hidden;
top: -15px;
left: -15px;
width: 30px;
height: 30px;
transform: rotate(45deg);
transform-origin: center;
background: red;
border: 2px solid blue;
animation: invert-spin 22.5s linear infinite;
}
.losange-1 .img {
position: relative;
width: 30px;
height: 30px;
}
.losange-1 .img:before {
position: absolute;
content: '';
display: block;
z-index: 999;
top: -15px;
left: -15px;
width: 60px;
height: 60px;
background: url("https://loremflickr.com/60/60/girl/all") center center;
transform: rotate(-45deg);
transform-origin: center;
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
/* Add some padding inside the card container */
.container {
padding: 2px 16px;
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes invert-spin {
100% {
-webkit-transform: rotate(-360deg);
transform: rotate(-360deg);
}
}
<div class="card">
<img src="http://placekitten.com/300/200" alt="Avatar" style="width:100%">
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
<div class="anim-square">
<div class="losange-wrap">
<div class="losange-1">
<div class="img"></div>
</div>
</div>
</div>
</div>
transform: rotate(45deg);
transform-origin: center;
background: red ;
border: 2px solid blue;
animation: invert-spin 22.5s linear infinite;
First you need to set the same duration for both animation then you need to use rotate(-315deg) for the image since you are setting rotate(45deg). The difference should be 360deg like the main container that will animate from 0deg to 360deg
.card {
/* Add shadows to create the "card" effect */
position: relative;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
width: 300px;
height: 300px;
margin: 150px auto;
}
.anim-square {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
//background: rgba(0,0,0,0.3);
animation: spin 5s linear infinite;
}
.losange-wrap {
position: relative;
}
.losange-1 {
position: absolute;
overflow: hidden;
top: -15px;
left: -15px;
width: 30px;
height: 30px;
transform: rotate(45deg);
transform-origin: center;
background: red;
border: 2px solid blue;
animation: invert-spin 5s linear infinite;
}
.losange-1 .img {
position: relative;
width: 30px;
height: 30px;
}
.losange-1 .img:before {
position: absolute;
content: '';
display: block;
z-index: 999;
top: -15px;
left: -15px;
width: 60px;
height: 60px;
background: url('https://loremflickr.com/60/60/girl/all') center center;
transform: rotate(-45deg);
transform-origin: center;
}
/* On mouse-over, add a deeper shadow */
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
/* Add some padding inside the card container */
.container {
padding: 2px 16px;
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes invert-spin {
100% {
-webkit-transform: rotate(-315deg);
transform: rotate(-315deg);
}
}
<div class="card">
<img src="http://placekitten.com/300/200" alt="Avatar" style="width:100%">
<div class="container">
<h4><b>John Doe</b></h4>
<p>Architect & Engineer</p>
</div>
<div class="anim-square">
<div class="losange-wrap">
<div class="losange-1">
<div class="img"></div>
</div>
</div>
</div>
</div>
When I hover over the image, the transition works fine except for the fact that the front image (that of a rotating lock) only translates 20px in Z direction when the mouse is removed from that image. I want the rotating lock image to be 20px in front always.
Also, why does the rotating lock image becomes slightly smaller just after I hover the image?
body {
margin:0;
width: 100%;
height: 100%;
}
.maincircle {
width: 200px;
height: 200px;
position: relative;
margin-left: 200px;
margin-top: 10px;
border-radius: 50%;
border: 1px solid black;
perspective: 600px;
transform-style: preserve-3d;
}
.door {
background-color: gray;
border-radius: 100%;
height: 200px;
margin: 0;
position: relative;
width: 200px;
transition: .5s linear;
transform-style: preserve-3d;
transform-origin: 0 50%;
transition: transform 2s 0.5s;
}
.door:before {
background-color: gray;
background-image: linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
border-radius: 100%;
content: '';
height: 200px;
left: 0;
position: absolute;
top: 0;
width: 200px;
transform: translateZ(-5px);
}
.door:after {
background-color: gray;
background-image: linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
bottom: 0;
content: '';
left: 100px;
position: absolute;
top: 0;
width: 5px;
z-index: -10;
transform: rotateY(-90deg);
transform-origin: 100% 50%;
}
.maincircle:hover .door {
transform: rotateY(-110deg);
}
.maincircle:hover .locker {
transform: rotate(90deg);
}
.locker {
background-image: url("https://irp-cdn.multiscreensite.com/806e9122/dms3rep/multi/tablet/CombinationLock-1000x1000.png");
position: absolute;
top: 25px;
left: 25px;
background-size: 100% 100%;
border-radius: 100%;
width: 150px;
height: 150px;
transform: translateZ(20px);
transition: transform 0.5s;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="maincircle">
<div class="door">
<div class="locker"></div>
</div>
</div>
</body>
</html>
Question 1: (I want the rotating lock image to be 20px in front always)
It is because transform settings are not additive in nature. When you specify the transform during the :hover as give below,
.maincircle:hover .locker {
transform: rotate(90deg);
}
it overwrites the transform: translateZ(20px) that is specified within the default state (which is the setting under .locker selector) and so the translation in Z-axis is lost whenever the element is being hovered. It gets applied back only when the :hover is off (that is, the element returns to default state as specified in .locker selector).
In order to always have the translation in Z-axis, translateZ(20px) should be added to the transform stack within :hover selector also like below:
.maincircle:hover .locker {
transform: rotate(90deg) translateZ(20px);
}
body {
margin:0;
width: 100%;
height: 100%;
}
.maincircle {
width: 200px;
height: 200px;
position: relative;
margin-left: 200px;
margin-top: 10px;
border-radius: 50%;
border: 1px solid black;
perspective: 600px;
transform-style: preserve-3d;
}
.door {
background-color: gray;
border-radius: 100%;
height: 200px;
margin: 0;
position: relative;
width: 200px;
transition: .5s linear;
transform-style: preserve-3d;
transform-origin: 0 50%;
transition: transform 2s 0.5s;
}
.door:before {
background-color: gray;
background-image: linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
border-radius: 100%;
content: '';
height: 200px;
left: 0;
position: absolute;
top: 0;
width: 200px;
transform: translateZ(-5px);
}
.door:after {
background-color: gray;
background-image: linear-gradient(hsla(0,0%,100%,.25), hsla(0,0%,0%,.25));
bottom: 0;
content: '';
left: 100px;
position: absolute;
top: 0;
width: 5px;
z-index: -10;
transform: rotateY(-90deg);
transform-origin: 100% 50%;
}
.maincircle:hover .door {
transform: rotateY(-110deg);
}
.maincircle:hover .locker {
transform: rotate(90deg) translateZ(20px);
}
.locker {
background-image: url("https://irp-cdn.multiscreensite.com/806e9122/dms3rep/multi/tablet/CombinationLock-1000x1000.png");
position: absolute;
top: 25px;
left: 25px;
background-size: 100% 100%;
border-radius: 100%;
width: 150px;
height: 150px;
transform: translateZ(20px);
transition: transform 0.5s;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="maincircle">
<div class="door">
<div class="locker"></div>
</div>
</div>
</body>
</html>
Question 2: (Why does the rotating lock image becomes slightly smaller just after I hover the image?)
I am putting this at the last (even below the code) because I know by now you'd have guessed why it became smaller. It becomes smaller because the element is losing the translateZ(20px) and so it is going farther away from your eye. Any object that goes farther away from the eye will look smaller.
In the fiddle below — I want the divs to fill in from the center, instead of from the top/left.
I've seen examples where margins are set in the keyframe, but that looks forever unclean to me.
Also, could I do this with transitions instead, is animate the best way to do this?
Here's the fiddle https://jsfiddle.net/hogue/mu0f6mk1/
.wrap {
position: relative;
margin: 0 auto;
width: 600px;
height: 600px;
cursor: pointer;
}
.wrap div {
border-radius: 10px;
box-shadow: inset 0 0 45px rgba(255, 255, 255, .3), 0 12px 20px -10px rgba(0, 0, 0, .4);
color: #FFF;
text-align: center;
text-shadow: 0 1px rgba(0, 0, 0, .3);
font: bold 3em sans-serif;
}
.first-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
-webkit-animation: firstLayer 2s ease-in 0s forwards;
}
.second-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
top: 8.5%;
left: 8.5%;
-webkit-animation: secondLayer 2s ease-in 0s forwards;
}
.third-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
top: 17%;
left: 17%;
-webkit-animation: thirdLayer 2s ease-in 0s forwards;
}
.fourth-layer {
background: #95a5a6;
width: 0px;
height: 0px;
position: absolute;
top: 25%;
left: 25%;
-webkit-animation: fourthLayer 2s ease-in 0s forwards;
}
#-webkit-keyframes firstLayer {
to {
width: 400px;
height: 400px;
}
}
#-webkit-keyframes secondLayer {
to {
width: 300px;
height: 300px;
}
}
#-webkit-keyframes thirdLayer {
to {
width: 200px;
height: 200px;
}
}
#-webkit-keyframes fourthLayer {
to {
width: 100px;
height: 100px;
}
}
<div class="wrap">
<div class="first-layer"></div>
<div class="second-layer"></div>
<div class="third-layer"></div>
<div class="fourth-layer"></div>
</div>
I have repaired you the code
#-webkit-keyframes firstLayer {
from {
width: 0px;
margin-left: 0;
margin-top: 0;
height: 0px;
}
to {
width: 400px;
margin-left: -200px;
margin-top: -200px;
height: 400px;
}
}