|
| 1 | +@charset "utf-8"; |
| 2 | +/* |
| 3 | +Copyright (c) 2021 by Jon Ambas (https://codepen.io/jonambas/pen/OPqbzx) |
| 4 | +
|
| 5 | +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 6 | +documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
| 7 | +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 | +persons to whom the Software is furnished to do so, subject to the following conditions: |
| 9 | +
|
| 10 | +The above copyright notice and this permission notice shall be included in all copies or substantial |
| 11 | +portions of the Software. |
| 12 | +
|
| 13 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 14 | +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 15 | +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 16 | + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 17 | + */ |
| 18 | +$cube-size: 85; |
| 19 | +$animation-duration: 7.7s; |
| 20 | +$easing: cubic-bezier(0.645, 0.045, 0.355, 1); |
| 21 | +$base-matrix: matrix(0.9, 0.5, 0, 1, 0, 0); |
| 22 | + |
| 23 | +@import "colors"; |
| 24 | + |
| 25 | +@function base($n) { |
| 26 | + @return $n * ($cube-size - 1px); |
| 27 | +} |
| 28 | + |
| 29 | +.layer { |
| 30 | + position: absolute; |
| 31 | + width: 100%; |
| 32 | + height: 100%; |
| 33 | + &.top { |
| 34 | + animation: $animation-duration top $easing infinite; |
| 35 | + } |
| 36 | + &.bottom { |
| 37 | + animation: $animation-duration bottom $easing infinite; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +$radial-map: ( |
| 42 | + "n": ( |
| 43 | + x1: base(1), |
| 44 | + y1: base(-1), |
| 45 | + x2: base(1), |
| 46 | + y2: base(-1), |
| 47 | + x3: base(2), |
| 48 | + y3: base(-2), |
| 49 | + x4: base(2), |
| 50 | + y4: base(-2) |
| 51 | + ), |
| 52 | + "s": ( |
| 53 | + x1: base(-1), |
| 54 | + y1: base(1), |
| 55 | + x2: base(-1), |
| 56 | + y2: base(1), |
| 57 | + x3: base(-2), |
| 58 | + y3: base(2), |
| 59 | + x4: base(-2), |
| 60 | + y4: base(2) |
| 61 | + ), |
| 62 | + "e": ( |
| 63 | + x1: base(1), |
| 64 | + y1: 0, |
| 65 | + x2: base(2), |
| 66 | + y2: 0, |
| 67 | + x3: base(2), |
| 68 | + y3: 0, |
| 69 | + x4: base(1), |
| 70 | + y4: 0 |
| 71 | + ), |
| 72 | + "w": ( |
| 73 | + x1: base(-1), |
| 74 | + y1: 0, |
| 75 | + x2: base(-2), |
| 76 | + y2: 0, |
| 77 | + x3: base(-2), |
| 78 | + y3: 0, |
| 79 | + x4: base(-1), |
| 80 | + y4: 0 |
| 81 | + ), |
| 82 | + "ne": ( |
| 83 | + x1: base(2), |
| 84 | + y1: base(-1), |
| 85 | + x2: base(3), |
| 86 | + y2: base(-1), |
| 87 | + x3: base(4), |
| 88 | + y3: base(-2), |
| 89 | + x4: base(3), |
| 90 | + y4: base(-2) |
| 91 | + ), |
| 92 | + "se": ( |
| 93 | + x1: 0, |
| 94 | + y1: base(1), |
| 95 | + x2: base(1), |
| 96 | + y2: base(1), |
| 97 | + x3: base(0), |
| 98 | + y3: base(2), |
| 99 | + x4: base(-1), |
| 100 | + y4: base(2) |
| 101 | + ), |
| 102 | + "sw": ( |
| 103 | + x1: base(-2), |
| 104 | + y1: base(1), |
| 105 | + x2: base(-3), |
| 106 | + y2: base(1), |
| 107 | + x3: base(-4), |
| 108 | + y3: base(2), |
| 109 | + x4: base(-3), |
| 110 | + y4: base(2) |
| 111 | + ), |
| 112 | + "nw": ( |
| 113 | + x1: base(0), |
| 114 | + y1: base(-1), |
| 115 | + x2: base(-1), |
| 116 | + y2: base(-1), |
| 117 | + x3: base(0), |
| 118 | + y3: base(-2), |
| 119 | + x4: base(1), |
| 120 | + y4: base(-2) |
| 121 | + ) |
| 122 | +); |
| 123 | + |
| 124 | +@each $position, $points in $radial-map { |
| 125 | + .#{$position} { |
| 126 | + animation: $animation-duration $position $easing infinite; |
| 127 | + } |
| 128 | + @keyframes #{$position} { |
| 129 | + 0%, |
| 130 | + 83.33%, |
| 131 | + 100% { |
| 132 | + transform: $base-matrix |
| 133 | + translate(map-get($points, x1), map-get($points, y1)); |
| 134 | + } |
| 135 | + 16.66% { |
| 136 | + transform: $base-matrix |
| 137 | + translate(map-get($points, x2), map-get($points, y2)); |
| 138 | + } |
| 139 | + 33.33%, |
| 140 | + 50% { |
| 141 | + transform: $base-matrix |
| 142 | + translate(map-get($points, x3), map-get($points, y3)); |
| 143 | + } |
| 144 | + 66.66% { |
| 145 | + transform: $base-matrix |
| 146 | + translate(map-get($points, x4), map-get($points, y4)); |
| 147 | + } |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +.cube { |
| 152 | + position: absolute; |
| 153 | + top: 45%; |
| 154 | + left: 45%; |
| 155 | + width: $cube-size + 0px; |
| 156 | + height: $cube-size + 0px; |
| 157 | + margin: 0 auto; |
| 158 | + background: $orange; |
| 159 | + transform: $base-matrix; |
| 160 | + |
| 161 | + &:before, |
| 162 | + &:after { |
| 163 | + display: block; |
| 164 | + content: ""; |
| 165 | + position: absolute; |
| 166 | + width: 100%; |
| 167 | + height: 100%; |
| 168 | + } |
| 169 | + |
| 170 | + &:before { |
| 171 | + background: $warning; |
| 172 | + transform: matrix(1, -1, 1, 0, $cube-size / 2, -$cube-size); |
| 173 | + } |
| 174 | + |
| 175 | + &:after { |
| 176 | + background: $link; |
| 177 | + transform: matrix(1, -1, 0, 1, $cube-size, -$cube-size / 2); |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +@keyframes top { |
| 182 | + 0%, |
| 183 | + 33.33%, |
| 184 | + 100% { |
| 185 | + transform: translate(0, base(-1)); |
| 186 | + } |
| 187 | + 50%, |
| 188 | + 83.33% { |
| 189 | + transform: translate(0, base(-2)); |
| 190 | + } |
| 191 | +} |
| 192 | +@keyframes bottom { |
| 193 | + 0%, |
| 194 | + 33.33%, |
| 195 | + 100% { |
| 196 | + transform: translate(0, base(1)); |
| 197 | + } |
| 198 | + 50%, |
| 199 | + 83.33% { |
| 200 | + transform: translate(0, base(2)); |
| 201 | + } |
| 202 | +} |
0 commit comments