$speed: 1s; $l: 50px; $rows: 6; $cols: 6; $h: $l*$rows; $w: $l*$cols; $cubes: $rows*$cols; //$timing: cubic-bezier(1,0.49,0.69,1); $timing: linear; $delay: $speed/$cubes; //$delay: 0; body { background: #306989; } .wall { position: relative; perspective: 700px; height: $h; width: $w; margin: 5vh auto; display: flex; flex-flow: wrap; visibility: hidden; &, * { backface-visibility: hidden; transform-style: preserve-3d; } .overlay { visibility: visible; position: absolute; display: block; top: 0; left: 0; width: $w; height: $h; transform: translatez($l/2); background-size: $w $h; transition: opacity 0.1s; } } .nav { position: absolute; top: 50%; left: $l*(-2/sqrt(2)); right: $l*(-2/sqrt(2)); height: 2px; .button { position: absolute; z-index: 99; top: 50%; height: $l; width: $l; margin-top: $l/-2; color: #888; font-family: monospace; text-align: center; cursor: pointer; visibility: visible; svg { position: relative; width: auto; margin: auto; height: 100%; } path { fill: currentcolor; } &:hover { color: #000; } &.prev { left: 0; } &.next { right: 0; } } } .cube { flex: 0 0 $l; height: $l; position: relative; pointer-events: none; animation-duration: $speed; animation-timing-function: $timing; animation-fill-mode: forwards; &.sliding { animation-play-state: running; &.up { animation-name: switch-up; } &.down { animation-name: switch-down; } &.left { animation-name: switch-left; } &.right { animation-name: switch-right; } @at-root { @keyframes switch-up { 0% , 10%{ transform: scale(1) rotatex(0); } 40% { transform: scale(1/sqrt(2)) translatez($l) rotatex(0); } 70% { transform: scale(1/sqrt(2)) translatez($l) rotatex(90deg); } 100% { transform: scale(1) rotatex(90deg); } } } @at-root { @keyframes switch-right { 0% , 10%{ transform: scale(1) rotatey(0); } 40% { transform: scale(1/sqrt(2)) translatez($l) rotatey(0); } 70% { transform: scale(1/sqrt(2)) translatez($l) rotatey(-90deg); } 100% { transform: scale(1) rotatey(-90deg); } } } @at-root { @keyframes switch-left { 0% , 10%{ transform: scale(1) rotatey(0); } 40% { transform: scale(1/sqrt(2)) translatez($l) rotatey(0); } 70% { transform: scale(1/sqrt(2)) translatez($l) rotatey(90deg); } 100% { transform: scale(1) rotatey(90deg); } } } @at-root { @keyframes switch-down { 0% , 10%{ transform: scale(1) rotatex(0); } 40% { transform: scale(1/sqrt(2)) translatez($l) rotatex(0); } 70% { transform: scale(1/sqrt(2)) translatez($l) rotatex(-90deg); } 100% { transform: scale(1) rotatex(-90deg); } } } } @for $i from 1 through $cubes { &:nth-child(#{$i}) { animation-delay: $delay*$i; .side { background-position: ($l*-1*($i%$cols) + $l) ($l*-1*ceil($i/$cols) + $l); } } } .side { visibility: visible; position: absolute; top: 0; left: 0; width: $l; height: $l; background-size: $w $h; background-color: #000; @for $i from 0 to 6 { &:nth-child(#{$i + 1}) { transform: if($i == 2 , rotate(180deg), rotate(0deg)) if($i < 4, rotateY($i*90deg) , rotateX(pow(-1, $i)*90deg)) translateZ($l/2); } } } }