I'm trying to create a folding effect in a hexagon composed of triangles. So far I've only managed to make the triangles translate instead of folding over. I want to make
this http://jsfiddle.net/zn6jbhr6/
Relevant SCSS
#mixin hexTranslateKeyFrames($name, $degree) {
#keyframes #{$name} {
#content;
}
}
$hex-degree: 0deg;
#for $idx from 1 through 6 {
$hex-degree: $hex-degree + 60;
#include hexTranslateKeyFrames(hexTranslate#{$idx}, $hex-degree) {
0% { transform: rotateZ(0deg) rotate($hex-degree); }
54.55%, 100% { transform: rotateZ(360deg) rotate($hex-degree); }
}
}
$order2: (0s, 0.2s, 0.4s, 0.6s, 0.8s, 1s);
.folding-hex {
#include hexagon();
#for $i from 1 through 6 {
.triangle:nth-child(#{$i}) {
animation: hexTranslate#{$i} 2.2s infinite #{nth($order2, $i)} linear;
}
}
}
more like this http://jsfiddle.net/wvm15yL4/
Relevant CSS
.sk-folding-cube .sk-cube {
float: left;
width: 50%;
height: 50%;
position: relative;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
.sk-folding-cube .sk-cube:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333;
-webkit-animation: sk-foldCubeAngle 2.4s infinite linear both;
animation: sk-foldCubeAngle 2.4s infinite linear both;
-webkit-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
.sk-folding-cube .sk-cube2 {
-webkit-transform: scale(1.1) rotateZ(90deg);
transform: scale(1.1) rotateZ(90deg);
}
.sk-folding-cube .sk-cube3 {
-webkit-transform: scale(1.1) rotateZ(180deg);
transform: scale(1.1) rotateZ(180deg);
}
.sk-folding-cube .sk-cube4 {
-webkit-transform: scale(1.1) rotateZ(270deg);
transform: scale(1.1) rotateZ(270deg);
}
.sk-folding-cube .sk-cube2:before {
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.sk-folding-cube .sk-cube3:before {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.sk-folding-cube .sk-cube4:before {
-webkit-animation-delay: 0.9s;
animation-delay: 0.9s;
}
#-webkit-keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
} 25%, 75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
} 90%, 100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
#keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
} 25%, 75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
} 90%, 100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
You need to create an animation that rotates in 3D.
Since it is a little hard, I have done it only once, and reused it for the other elements setting an intermediate element in the DOM that does the rotation in the plane
The first 2 parameters in the rotate3D are sin(60deg) and cos(60deg), to make the rotation axis be at 60 deg
#keyframes flip {
0% { transform: rotate3d( 0.5, 0.866, 0, 90deg);
opacity: 0;}
0.1% { transform: rotate3d( 0.5, 0.866, 0, 90deg);
opacity: 1;}
14% { transform: rotate3d( 0.5, 0.866, 0, 0deg); }
50% { transform: rotate3d(-0.5, 0.866, 0, 0deg); }
63.99% { transform: rotate3d(-0.5, 0.866, 0, -90deg);
opacity: 1;}
64%, 100% { transform: rotate3d(-0.5, 0.866, 0, -90deg);
opacity: 0}
}
.folding-hex {
height: 69.28px;
width: 80px;
position: relative;
margin: 0 auto;
transform-origin: 0 0;
transform: translateX(40px) rotate(30deg); }
.rotator {
transform-origin: 20px 37.64px;
}
.rotator:nth-child(1) {
transform: rotate(0deg);
}
.rotator:nth-child(2) {
transform: rotate(60deg);
}
.rotator:nth-child(3) {
transform: rotate(120deg);
}
.rotator:nth-child(4) {
transform: rotate(180deg);
}
.rotator:nth-child(5) {
transform: rotate(240deg);
}
.rotator:nth-child(6) {
transform: rotate(300deg);
}
.triangle {
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 34.64px 20px 0;
transform-origin: 20px 37.64px;
border-color: #E50C4E transparent;
animation: flip 3s linear infinite;
}
.rotator:nth-child(2) .triangle {
border-color: #b5093d transparent;
animation-delay: -2.5s;
}
.rotator:nth-child(3) .triangle {
border-color: #b5093d transparent;
animation-delay: -2.0s;
}
.rotator:nth-child(4) .triangle {
animation-delay: -1.5s;
}
.rotator:nth-child(5) .triangle {
border-color: #f8799f transparent;
animation-delay: -1.0s;
}
.rotator:nth-child(6) .triangle {
border-color: #f8799f transparent;
animation-delay: -0.5s;
}
<div class="folding-hex">
<div class="rotator">
<div class="triangle"></div>
</div>
<div class="rotator">
<div class="triangle"></div>
</div>
<div class="rotator">
<div class="triangle"></div>
</div>
<div class="rotator">
<div class="triangle"></div>
</div>
<div class="rotator">
<div class="triangle"></div>
</div>
<div class="rotator">
<div class="triangle"></div>
</div>
</div>
Related
<style>
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.main-cube-wrapper {
height: 80px;
position: relative;
margin-top: 2rem;
}
.wrap {
-webkit-perspective: 1000px;
perspective: 1000px;
-webkit-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.cube {
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
width: 80px;
height: 80px;
margin: auto;
-webkit-animation-name: rotate;
animation-name: rotate;
-webkit-animation-duration: 30s;
animation-duration: 30s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
.cube div {
position: absolute;
opacity: 0.7;
width: 80px;
height: 80px;
}
.face-1 {
background: red;
-webkit-transform: rotateY(0deg) translateZ(40px);
transform: rotateY(0deg) translateZ(40px);
}
.face-2 {
background: green;
-webkit-transform: rotateY(90deg) translateZ(40px);
transform: rotateY(90deg) translateZ(40px);
}
.face-3 {
background: blue;
-webkit-transform: rotateY(180deg) translateZ(40px);
transform: rotateY(180deg) translateZ(40px);
}
.face-4 {
background: yellow;
-webkit-transform: rotateY(-90deg) translateZ(40px);
transform: rotateY(-90deg) translateZ(40px);
}
.face-5 {
background: purple;
-webkit-transform: rotateX(90deg) translateZ(40px);
transform: rotateX(90deg) translateZ(40px);
}
.face-6 {
background: orange;
-webkit-transform: rotateX(-90deg) translateZ(40px);
transform: rotateX(-90deg) translateZ(40px);
}
#-webkit-keyframes rotate {
0% {
-webkit-transform: rotate3d(0, 0, 0, 0);
transform: rotate3d(0, 0, 0, 0);
}
100% {
-webkit-transform: rotate3d(0, 1, 0, 360deg);
transform: rotate3d(0, 1, 0, 360deg);
}
}
#keyframes rotate {
0% {
-webkit-transform: rotate3d(0, 0, 0, 0);
transform: rotate3d(0, 0, 0, 0);
}
100% {
-webkit-transform: rotate3d(0, 1, 0, 360deg);
transform: rotate3d(0, 1, 0, 360deg);
}
}
</style>
<div class="main-cube-wrapper">
<div class="wrap">
<div class="cube">
<div class="face-1"></div>
<div class="face-2"></div>
<div class="face-3"></div>
<div class="face-4"></div>
<div class="face-5"></div>
<div class="face-6"></div>
</div>
</div>
</div>
I am learning and working on some project I have created the rotating cube using SCSS, and I have already checked that the cube translates or rotates in every browser except 'Safari browser'. Can anybody please help me solving this issue so the cube can also rotate and work properly in the safari browser.
See update below
It look like Safari has issues with rotate3d. Just test this example on your Safari browser. The last rotation using rotateZ should work.
div {
width: 100px;
height: 100px;
background: red;
margin: 20px;
}
.rotate-2d { -webkit-animation: rotate-2d 1s linear infinite; }
.rotate-3d { -webkit-animation: rotate-3d 1s linear infinite; }
.rotate-3d-v2 { -webkit-animation: rotate-3d-v2 1s linear infinite; }
div:after {
content: 'A';
display: inline-block;
width: 10px;
height: 20px;
color: green;
font-size: 100px;
}
#-webkit-keyframes rotate-2d {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#-webkit-keyframes rotate-3d {
0% {
-webkit-transform: rotate3d(0,0,1,0deg);
}
100% {
-webkit-transform: rotate3d(0,0,1,360deg);
}
}
#-webkit-keyframes rotate-3d-v2 {
0% {
-webkit-transform: rotateZ(0deg);
}
100% {
-webkit-transform: rotateZ(360deg);
}
}
<div class="rotate-2d"></div>
<div class="rotate-3d"></div>
<div class="rotate-3d-v2"></div>
Update
Seems Safari has an issue to recognise the change between two key frames. Adding an intermediate keyframe seem to solve the problem:
.main-cube-wrapper {
height: 180px;
position: relative;
margin-top: 2rem;
}
.wrap {
-webkit-perspective: 1000px;
perspective: 1000px;
-webkit-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.cube {
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
width: 80px;
height: 80px;
margin: auto;
-webkit-animation-name: rotate;
animation-name: rotate;
-webkit-animation-duration: 30s;
animation-duration: 30s;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}
.cube div {
position: absolute;
opacity: 0.7;
width: 80px;
height: 80px;
}
.face-1 {
background: red;
-webkit-transform: rotateY(0deg) translateZ(40px);
transform: rotateY(0deg) translateZ(40px);
}
.face-2 {
background: green;
-webkit-transform: rotateY(90deg) translateZ(40px);
transform: rotateY(90deg) translateZ(40px);
}
.face-3 {
background: blue;
-webkit-transform: rotateY(180deg) translateZ(40px);
transform: rotateY(180deg) translateZ(40px);
}
.face-4 {
background: yellow;
-webkit-transform: rotateY(-90deg) translateZ(40px);
transform: rotateY(-90deg) translateZ(40px);
}
.face-5 {
background: purple;
-webkit-transform: rotateX(90deg) translateZ(40px);
transform: rotateX(90deg) translateZ(40px);
}
.face-6 {
background: orange;
-webkit-transform: rotateX(-90deg) translateZ(40px);
transform: rotateX(-90deg) translateZ(40px);
}
#-webkit-keyframes rotate {
0% {
transform: rotate3d(0, 0, 0, 0);
}
50% {
transform: rotate3d(0, 1, 0, 180deg);
}
100% {
transform: rotate3d(0, 1, 0, 360deg);
}
}
<div class="main-cube-wrapper">
<div class="wrap">
<div class="cube">
<div class="face-1"></div>
<div class="face-2"></div>
<div class="face-3"></div>
<div class="face-4"></div>
<div class="face-5"></div>
<div class="face-6"></div>
</div>
</div>
</div>
i want to rotate the cube and its faces expanded. i have tried something like below,
.wrapper{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.cube-wrap {
width: 40px;
height: 40px;
-webkit-perspective: 2000px;
-webkit-perspective-origin: 50% -500px;
}
.single-box {
background-size: cover;
display: block;
position: absolute;
width: 40px;
height: 40px;
background-color: #60c2ef;
-webkit-transform: rotateY(45deg) translateZ(-200px) rotateX(15deg);
-webkit-transform-origin: 50% 50% 0;
}
.box {
-webkit-transform-style: preserve-3d;
-webkit-animation: rotate 1.5s infinite ease;
}
.side-front {
animation: side-front-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(0deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: translateZ(20px);
}
.side-back {
animation: side-back-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(-180deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
border: #ffffff;
-webkit-transform: rotateY(180deg) translateZ(20px);
}
.side-top {
animation: side-top-animation 3s ease infinite;
animation-delay: 0;
transform: rotateX(90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateX(90deg) translateZ(20px);
}
.side-bottom {
animation: side-bottom-animation 3s ease infinite;
animation-delay: 0;
transform: rotateX(-90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateX(-90deg) translateZ(20px);
}
.side-left {
animation: side-left-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(-90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateY(-90deg) translateZ(20px);
}
.side-right {
animation: side-right-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateY(90deg) translateZ(20px);
}
#-webkit-keyframes rotate {
0% { -webkit-transform: rotateY(0); }
100% { -webkit-transform: rotateY(360deg); }
}
#-webkit-keyframes side-top-animation {
0% { opacity: 1; transform: rotateX(90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateX(90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateX(90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateX(90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateX(90deg) translateZ(150px) }
}
#-webkit-keyframes side-bottom-animation {
0% { opacity: 1; transform: rotateX(-90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateX(-90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateX(-90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateX(-90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateX(-90deg) translateZ(150px) }
}
#-webkit-keyframes side-front-animation {
0% { opacity: 1; transform: rotateY(0deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(0deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(0deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(0deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(0deg) translateZ(150px) }
}
#-webkit-keyframes side-back-animation {
0% { opacity: 1; transform: rotateY(-180deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(-180deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(-180deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(-180deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(-180deg) translateZ(150px) }
}
#-webkit-keyframes side-left-animation {
0% { opacity: 1; transform: rotateY(-90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(-90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(-90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(-90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(-90deg) translateZ(150px) }
}
#-webkit-keyframes side-right-animation {
0% { opacity: 1; transform: rotateY(90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(90deg) translateZ(150px) }
}
<div class="wrapper">
<div class="cube-wrap">
<div class="box">
<div class="single-box side-back"></div>
<div class="single-box side-top"></div>
<div class="single-box side-bottom"></div>
<div class="single-box side-left"></div>
<div class="single-box side-right"></div>
<div class="single-box side-front"></div>
</div>
</div>
</div>
The above code works. it rotates and spins but the faces are not close enough to look like a cube. how can i fix this.
could someone help me with this. thanks.
I am not knowing how to add the animations to the cube faces. and the cube should like in image below.
In your code change the height and width of .single-box to 150px to match make a box, then to compensate the changes in the animation also change the height and width of .cube-wrap to the same value of .single-box.
So you get something like this
.wrapper{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.cube-wrap {
width: 130px;
height: 130px;
-webkit-perspective: 2000px;
-webkit-perspective-origin: 50% -500px;
}
.single-box {
background-size: cover;
display: block;
position: absolute;
width: 130px;
height: 130px;
background-color: #60c2ef;
-webkit-transform: rotateY(45deg) translateZ(-200px) rotateX(15deg);
-webkit-transform-origin: 50% 50% 0;
}
.box {
-webkit-transform-style: preserve-3d;
-webkit-animation: rotate 1.5s infinite ease;
}
.side-front {
animation: side-front-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(0deg) translateZ(300px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: translateZ(20px);
}
.side-back {
animation: side-back-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(-180deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
border: #ffffff;
-webkit-transform: rotateY(180deg) translateZ(20px);
}
.side-top {
animation: side-top-animation 3s ease infinite;
animation-delay: 0;
transform: rotateX(90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateX(90deg) translateZ(20px);
}
.side-bottom {
animation: side-bottom-animation 3s ease infinite;
animation-delay: 0;
transform: rotateX(-90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateX(-90deg) translateZ(20px);
}
.side-left {
animation: side-left-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(-90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateY(-90deg) translateZ(20px);
}
.side-right {
animation: side-right-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateY(90deg) translateZ(20px);
}
#-webkit-keyframes rotate {
0% { -webkit-transform: rotateY(0); }
100% { -webkit-transform: rotateY(360deg); }
}
#-webkit-keyframes side-top-animation {
0% { opacity: 1; transform: rotateX(90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateX(90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateX(90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateX(90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateX(90deg) translateZ(150px) }
}
#-webkit-keyframes side-bottom-animation {
0% { opacity: 1; transform: rotateX(-90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateX(-90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateX(-90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateX(-90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateX(-90deg) translateZ(150px) }
}
#-webkit-keyframes side-front-animation {
0% { opacity: 1; transform: rotateY(0deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(0deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(0deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(0deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(0deg) translateZ(150px) }
}
#-webkit-keyframes side-back-animation {
0% { opacity: 1; transform: rotateY(-180deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(-180deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(-180deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(-180deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(-180deg) translateZ(150px) }
}
#-webkit-keyframes side-left-animation {
0% { opacity: 1; transform: rotateY(-90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(-90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(-90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(-90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(-90deg) translateZ(150px) }
}
#-webkit-keyframes side-right-animation {
0% { opacity: 1; transform: rotateY(90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(90deg) translateZ(150px) }
}
<div class="wrapper">
<div class="cube-wrap">
<div class="box">
<div class="single-box side-back"></div>
<div class="single-box side-top"></div>
<div class="single-box side-bottom"></div>
<div class="single-box side-left"></div>
<div class="single-box side-right"></div>
<div class="single-box side-front"></div>
</div>
</div>
</div>
In my project, when the homepage is opened, it should run a CSS animation so that the cube's faces open. After the animation is complete the faces should remain. So I need to modify this code, because as it is the faces open and then close. After they open the faces should remain on the screen instead of closing.
How can I do this?
.sk-folding-cube {
margin: 20px auto;
width: 40px;
height: 40px;
position: relative;
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
.sk-folding-cube .sk-cube {
float: left;
width: 50%;
height: 50%;
position: relative;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
.sk-folding-cube .sk-cube:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333;
-webkit-animation: sk-foldCubeAngle 2.4s 1 linear both;
animation: sk-foldCubeAngle 2.4s 1 linear both;
-webkit-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
.sk-folding-cube .sk-cube2 {
-webkit-transform: scale(1.1) rotateZ(90deg);
transform: scale(1.1) rotateZ(90deg);
}
.sk-folding-cube .sk-cube3 {
-webkit-transform: scale(1.1) rotateZ(180deg);
transform: scale(1.1) rotateZ(180deg);
}
.sk-folding-cube .sk-cube4 {
-webkit-transform: scale(1.1) rotateZ(270deg);
transform: scale(1.1) rotateZ(270deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube2:before {
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.sk-folding-cube .sk-cube3:before {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.sk-folding-cube .sk-cube4:before {
-webkit-animation-delay: 0.9s;
animation-delay: 0.9s;
}
.sk-folding-cube .sk-cube5:before {
-webkit-animation-delay: 1.2s;
animation-delay: 1.2s;
}
.sk-folding-cube .sk-cube6:before {
-webkit-animation-delay: 1.5s;
animation-delay: 1.5s;
}
#-webkit-keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
#keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
<html>
<head>
<link href="style.css" rel="stylesheet">
<title>Open Cube</title>
<h1>Apertura Cubo</h1>
</head>
<body>
<div class="sk-folding-cube">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
<div class="sk-cube5 sk-cube"></div>
<div class="sk-cube6 sk-cube"></div>
</div>
</body>
</html>
UPDATE
I need to have like result on the screen the first opening of the picture
One of the things specified by the animation property is how many times the animation should repeat. In your example you have specified 1, but by instead specifying 0.5 the animation will stop after half of the time.
.sk-folding-cube {
margin: 20px auto;
width: 40px;
height: 40px;
position: relative;
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
.sk-folding-cube .sk-cube {
float: left;
width: 50%;
height: 50%;
position: relative;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
.sk-folding-cube .sk-cube:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333;
-webkit-animation: sk-foldCubeAngle 2.4s 0.5 linear both;
animation: sk-foldCubeAngle 2.4s 0.5 linear both;
-webkit-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
.sk-folding-cube .sk-cube2 {
-webkit-transform: scale(1.1) rotateZ(90deg);
transform: scale(1.1) rotateZ(90deg);
}
.sk-folding-cube .sk-cube3 {
-webkit-transform: scale(1.1) rotateZ(180deg);
transform: scale(1.1) rotateZ(180deg);
}
.sk-folding-cube .sk-cube4 {
-webkit-transform: scale(1.1) rotateZ(270deg);
transform: scale(1.1) rotateZ(270deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube2:before {
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.sk-folding-cube .sk-cube3:before {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.sk-folding-cube .sk-cube4:before {
-webkit-animation-delay: 0.9s;
animation-delay: 0.9s;
}
.sk-folding-cube .sk-cube5:before {
-webkit-animation-delay: 1.2s;
animation-delay: 1.2s;
}
.sk-folding-cube .sk-cube6:before {
-webkit-animation-delay: 1.5s;
animation-delay: 1.5s;
}
#-webkit-keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
#keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
<html>
<head>
<link href="style.css" rel="stylesheet">
<title>Open Cube</title>
<h1>Apertura Cubo</h1>
</head>
<body>
<div class="sk-folding-cube">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
<div class="sk-cube5 sk-cube"></div>
<div class="sk-cube6 sk-cube"></div>
</div>
</body>
</html>
Change the opacity at 100% progress in the keyframes to 1. It is currently set to hide the frames after the animation is completed in the last keyframes.
See below where the final stage of the animation remains visible :
.sk-folding-cube {
margin: 20px auto;
width: 40px;
height: 40px;
position: relative;
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
.sk-folding-cube .sk-cube {
float: left;
width: 50%;
height: 50%;
position: relative;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
.sk-folding-cube .sk-cube:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333;
-webkit-animation: sk-foldCubeAngle 2.4s 1 linear both;
animation: sk-foldCubeAngle 2.4s 1 linear both;
-webkit-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
.sk-folding-cube .sk-cube2 {
-webkit-transform: scale(1.1) rotateZ(90deg);
transform: scale(1.1) rotateZ(90deg);
}
.sk-folding-cube .sk-cube3 {
-webkit-transform: scale(1.1) rotateZ(180deg);
transform: scale(1.1) rotateZ(180deg);
}
.sk-folding-cube .sk-cube4 {
-webkit-transform: scale(1.1) rotateZ(270deg);
transform: scale(1.1) rotateZ(270deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube2:before {
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.sk-folding-cube .sk-cube3:before {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.sk-folding-cube .sk-cube4:before {
-webkit-animation-delay: 0.9s;
animation-delay: 0.9s;
}
.sk-folding-cube .sk-cube5:before {
-webkit-animation-delay: 1.2s;
animation-delay: 1.2s;
}
.sk-folding-cube .sk-cube6:before {
-webkit-animation-delay: 1.5s;
animation-delay: 1.5s;
}
#-webkit-keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 1;
}
}
#keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 1;
}
}
<html>
<head>
<link href="style.css" rel="stylesheet">
<title>Open Cube</title>
<h1>Apertura Cubo</h1>
</head>
<body>
<div class="sk-folding-cube">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
<div class="sk-cube5 sk-cube"></div>
<div class="sk-cube6 sk-cube"></div>
</div>
</body>
</html>
In my project, when the homepage is opened, it should run a CSS animation so that the cube's faces open. After the animation is complete the faces should be like in the picture (I need to have a result like the first opening in the picture).
This is my code,
.sk-folding-cube {
margin: 20px auto;
width: 40px;
height: 40px;
position: relative;
}
.sk-folding-cube .sk-cube {
float: left;
width: 50%;
height: 50%;
position: relative;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
.sk-folding-cube .sk-cube:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #000000;
-webkit-animation: sk-foldCubeAngle 2.4s 0.5 linear both;
animation: sk-foldCubeAngle 2.4s 0.5 linear both;
-webkit-transform-origin: 100% 100%;
-ms-transform-origin: 100% 100%;
transform-origin: 100% 100%;
}
.sk-folding-cube .sk-cube2 {
-webkit-transform: scale(1.1) rotateZ(90deg);
transform: scale(1.1) rotateZ(90deg);
}
.sk-folding-cube .sk-cube3 {
-webkit-transform: scale(1.1) rotateZ(180deg);
transform: scale(1.1) rotateZ(180deg);
}
.sk-folding-cube .sk-cube4 {
-webkit-transform: scale(1.1) rotateZ(270deg);
transform: scale(1.1) rotateZ(270deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube5 {
-webkit-transform: scale(1.1) rotateZ(360deg);
transform: scale(1.1) rotateZ(360deg);
}
.sk-folding-cube .sk-cube2:before {
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.sk-folding-cube .sk-cube3:before {
-webkit-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.sk-folding-cube .sk-cube4:before {
-webkit-animation-delay: 0.9s;
animation-delay: 0.9s;
}
.sk-folding-cube .sk-cube5:before {
-webkit-animation-delay: 1.2s;
animation-delay: 1.2s;
}
.sk-folding-cube .sk-cube6:before {
-webkit-animation-delay: 1.5s;
animation-delay: 1.5s;
}
#-webkit-keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
#keyframes sk-foldCubeAngle {
0%, 10% {
-webkit-transform: perspective(140px) rotateX(-180deg);
transform: perspective(140px) rotateX(-180deg);
opacity: 0;
}
25%,
75% {
-webkit-transform: perspective(140px) rotateX(0deg);
transform: perspective(140px) rotateX(0deg);
opacity: 1;
}
90%,
100% {
-webkit-transform: perspective(140px) rotateY(180deg);
transform: perspective(140px) rotateY(180deg);
opacity: 0;
}
}
<html>
<head>
<link href="style.css" rel="stylesheet">
<title>Open Cube</title>
<h1>Apertura Cubo</h1>
</head>
<body>
<div class="sk-folding-cube">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
</div>
</body>
</html>
How can I do this?
Judging by the description, snippet and the picture provided in question it seems like you are trying to create a flat cube opening animation where each face of the cube opens one by one and ends up with the appearance as shown in the first sample within the picture.
It might be possible to achieve that effect by enhancing your current code but I found it a bit confusing and so went with my own version of a flat-cube.
Explanation:
First create a cube with six faces (one div element for each face). I've made the front face as a child element of the left face element because the front face should eventually get opened on the left hand side of the left face.
Each face is a 50 x 50px square whose transform and transform-origin properties are set in such a way that it creates a cube.
Opening animation is then attached to each of the faces and a delay is added depending on when each face should get opened. In the demo, the right face gets opened first and so it has no delay, the bottom face is opened second and so it has a delay of 1s (equal to the animation time of right face), the top face is opened third and so has a delay of 2s (equal to combined animation time of the previous two faces) and so on.
The back face doesn't have any animation attached because it doesn't need to open at all ;)
.cube {
position: relative;
margin: 100px;
transform-style: preserve-3d;
}
.cube div {
position: absolute;
height: 50px;
width: 50px;
transform-style: preserve-3d;
}
.back {
background: rebeccapurple;
}
.right {
background: tomato;
transform: rotateY(90deg);
transform-origin: right;
animation: open-y 1s ease-in-out forwards;
}
.bottom {
background: crimson;
transform: rotateX(270deg);
transform-origin: bottom;
animation: open-x 1s 1s ease-in-out forwards;
}
.top {
background: indianred;
transform: rotateX(90deg);
transform-origin: top;
animation: open-x 1s 2s ease-in-out forwards;
}
.left {
background: yellowgreen;
transform: rotateY(270deg);
transform-origin: left;
animation: open-y 1s 3s ease-in-out forwards;
}
.front {
background: chocolate;
transform: rotateY(270deg);
transform-origin: right;
animation: open-y 1s 3s ease-in-out forwards;
}
#keyframes open-y {
to {
transform: rotateY(180deg);
}
}
#keyframes open-x {
to {
transform: rotateX(180deg);
}
}
<div class="cube">
<div class="back"></div>
<div class="right"></div>
<div class="bottom"></div>
<div class="top"></div>
<div class="left">
<div class="front"></div>
</div>
</div>
Note: It is very much possible to achieve a similar effect in other ways also and in addition make them look a lot more realistic but that would most likely involve a good amount of translate transforms, extra keyframe settings for the animations etc - in short, a lot more complex code.
I have a problem regarding the positioning of my container.
Keeping the styles whilst removing the position: absolute; on the .dot seems to be proving rather tricky and with each attempt the dots are going all over the place!
To clarify, I'm looking at being able to move the entire loader
.sampleContainer {
float: left;
height: 40px;
width: 60px;
background: white;
}
.loader {
display: inline-block;
float: left;
margin-left:100px;
}
.dot {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 4px;
background: #888;
position: absolute;
}
.dot_1 {
animation: animateDot1 1.5s linear infinite;
left: 12px;
/**background: #e579b8;**/
}
.dot_2 {
animation: animateDot2 1.5s linear infinite;
animation-delay: 0.5s;
left: 24px;
}
.dot_3 {
animation: animateDot3 1.5s linear infinite;
left: 12px;
}
.dot_4 {
animation: animateDot4 1.5s linear infinite;
animation-delay: 0.5s;
left: 24px;
}
#keyframes animateDot1 {
0% { transform: rotate(0deg) translateX(-12px); }
25% { transform: rotate(180deg) translateX(-12px); }
75% { transform: rotate(180deg) translateX(-12px); }
100% { transform: rotate(360deg) translateX(-12px); }
}
#keyframes animateDot2 {
0% { transform: rotate(0deg) translateX(-12px); }
25% { transform: rotate(-180deg) translateX(-12px); }
75% { transform: rotate(-180deg) translateX(-12px); }
100% { transform: rotate(-360deg) translateX(-12px); }
}
#keyframes animateDot3 {
0% { transform: rotate(0deg) translateX(12px); }
25% { transform: rotate(180deg) translateX(12px); }
75% { transform: rotate(180deg) translateX(12px); }
100% { transform: rotate(360deg) translateX(12px); }
}
#keyframes animateDot4 {
0% { transform: rotate(0deg) translateX(12px); }
25% { transform: rotate(-180deg) translateX(12px); }
75% { transform: rotate(-180deg) translateX(12px); }
100% { transform: rotate(-360deg) translateX(12px); }
}
<div class="sampleContainer">
<div class="loader">
<span class="dot dot_1"></span>
<span class="dot dot_2"></span>
<span class="dot dot_3"></span>
<span class="dot dot_4"></span>
</div>
</div>
you need to set position:relative to parent, otherwise it will be out of the DOM flow.
As for my tests you don't need the .loader CSS
.sampleContainer {
float: left;
height: 40px;
width: 60px;
background: white;
position: relative;
background: lightblue;
}
.dot {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 4px;
background: #888;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 15px 8px
}
.dot_1 {
animation: animateDot1 1.5s linear infinite;
left: 12px;
/**background: #e579b8;**/
}
.dot_2 {
animation: animateDot2 1.5s linear infinite;
animation-delay: 0.5s;
left: 24px;
}
.dot_3 {
animation: animateDot3 1.5s linear infinite;
left: 12px;
}
.dot_4 {
animation: animateDot4 1.5s linear infinite;
animation-delay: 0.5s;
left: 24px;
}
#keyframes animateDot1 {
0% {
transform: rotate(0deg) translateX(-12px);
}
25% {
transform: rotate(180deg) translateX(-12px);
}
75% {
transform: rotate(180deg) translateX(-12px);
}
100% {
transform: rotate(360deg) translateX(-12px);
}
}
#keyframes animateDot2 {
0% {
transform: rotate(0deg) translateX(-12px);
}
25% {
transform: rotate(-180deg) translateX(-12px);
}
75% {
transform: rotate(-180deg) translateX(-12px);
}
100% {
transform: rotate(-360deg) translateX(-12px);
}
}
#keyframes animateDot3 {
0% {
transform: rotate(0deg) translateX(12px);
}
25% {
transform: rotate(180deg) translateX(12px);
}
75% {
transform: rotate(180deg) translateX(12px);
}
100% {
transform: rotate(360deg) translateX(12px);
}
}
#keyframes animateDot4 {
0% {
transform: rotate(0deg) translateX(12px);
}
25% {
transform: rotate(-180deg) translateX(12px);
}
75% {
transform: rotate(-180deg) translateX(12px);
}
100% {
transform: rotate(-360deg) translateX(12px);
}
}
<div style="float:left">Deleting 'Folder Name' folder</div>
<div class="sampleContainer">
<div class="loader">
<span class="dot dot_1"></span>
<span class="dot dot_2"></span>
<span class="dot dot_3"></span>
<span class="dot dot_4"></span>
</div>
</div>