- Dapatkan pautan
- X
- E-mel
- Apl Lain
Jangan keliru dan salah sangka dgn tajuk. Ini adalah contoh animasi CSS, bukan yg bukan-bukan.
Segi empat mengocok (Shuffling squares)
Demo
HTML view ▼
<div style="margin: 0; background: #45818e; height: 810px; position: relative; border-radius: 12px;">
<spanduk>
<amende>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
</amende>
<amende class="lak">
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
</amende>
</spanduk>
</div>
<style>
spanduk {
position: absolute;
display: block;
width: 450px;
height: 450px;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
amende {
margin: 0;
position: absolute;
}
figure {
position: absolute;
background: brown;
width: 150px;
height: 150px;
animation: idk2 2s ease infinite;
margin: 0;
}
.lak figure {
animation: idk2 2s ease infinite;
animation-direction: reverse;
}
figure:nth-child(2) {
left: 150px;
animation-delay: .5s;
}
figure:nth-child(3) {
left: 150px;
top: 150px;
animation-delay: 1s;
}
figure:nth-child(4) {
top: 150px;
animation-delay: 1.5s;
}
labu {
width: 50px;
height: 50px;
position: absolute;
background: #333;
animation: idk 2s ease infinite;
}
labu:nth-child(2) {
left: 50px;
animation-delay: .5s;
}
labu:nth-child(3) {
left: 50px;
top: 50px;
animation-delay: 1s;
}
labu:nth-child(4) {
top: 50px;
animation-delay: 1.5s;
}
@keyframes idk {
0% {
transform: translateX(0);
}
25% {
transform: translateX(50px) rotate(90deg);
}
50% {
transform: translateX(50px) translateY(50px) rotate(0);
}
75% {
transform: translateX(0) translateY(50px) rotate(90deg);
}
100% {
transform: translateX(0);
}
}
@keyframes idk2 {
0% {
transform: translateX(0);
}
25% {
transform: translateX(150px) rotate(90deg);
}
50% {
transform: translateX(150px) translateY(150px) rotate(0);
}
75% {
transform: translateX(0) translateY(150px) rotate(90deg);
}
100% {
transform: translateX(0);
}
}
</style>
<spanduk>
<amende>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
</amende>
<amende class="lak">
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
<figure>
<labu></labu><labu></labu><labu></labu><labu></labu>
</figure>
</amende>
</spanduk>
</div>
<style>
spanduk {
position: absolute;
display: block;
width: 450px;
height: 450px;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
amende {
margin: 0;
position: absolute;
}
figure {
position: absolute;
background: brown;
width: 150px;
height: 150px;
animation: idk2 2s ease infinite;
margin: 0;
}
.lak figure {
animation: idk2 2s ease infinite;
animation-direction: reverse;
}
figure:nth-child(2) {
left: 150px;
animation-delay: .5s;
}
figure:nth-child(3) {
left: 150px;
top: 150px;
animation-delay: 1s;
}
figure:nth-child(4) {
top: 150px;
animation-delay: 1.5s;
}
labu {
width: 50px;
height: 50px;
position: absolute;
background: #333;
animation: idk 2s ease infinite;
}
labu:nth-child(2) {
left: 50px;
animation-delay: .5s;
}
labu:nth-child(3) {
left: 50px;
top: 50px;
animation-delay: 1s;
}
labu:nth-child(4) {
top: 50px;
animation-delay: 1.5s;
}
@keyframes idk {
0% {
transform: translateX(0);
}
25% {
transform: translateX(50px) rotate(90deg);
}
50% {
transform: translateX(50px) translateY(50px) rotate(0);
}
75% {
transform: translateX(0) translateY(50px) rotate(90deg);
}
100% {
transform: translateX(0);
}
}
@keyframes idk2 {
0% {
transform: translateX(0);
}
25% {
transform: translateX(150px) rotate(90deg);
}
50% {
transform: translateX(150px) translateY(150px) rotate(0);
}
75% {
transform: translateX(0) translateY(150px) rotate(90deg);
}
100% {
transform: translateX(0);
}
}
</style>
CSS disesuaikan untuk paparan di blog ini, dicontoh dari codepen
Catatan oleh
Orandableg
- Dapatkan pautan
- X
- E-mel
- Apl Lain
Ulasan