|
| 1 | +.cssonly-slider { |
| 2 | + --width: 500px; |
| 3 | + --height: 300px; |
| 4 | + position: relative; |
| 5 | + width: var(--width); |
| 6 | + height: var(--height); |
| 7 | + margin: auto; |
| 8 | + |
| 9 | + input[type=radio] { |
| 10 | + display: none; |
| 11 | + } |
| 12 | + |
| 13 | + .slides-wrapper { |
| 14 | + height: 100%; |
| 15 | + width: 100%; |
| 16 | + overflow: hidden; |
| 17 | + } |
| 18 | + |
| 19 | + .slides { |
| 20 | + display: inline-flex; |
| 21 | + flex-wrap: nowrap; |
| 22 | + min-width: 100%; |
| 23 | + height: 100%; |
| 24 | + transition: transform 0.3s ease-in-out; |
| 25 | + // animation: cssonlySlider 8s linear infinite; |
| 26 | + // animation-timing-function: steps(4, jump-none); |
| 27 | + // animation-play-state: paused; |
| 28 | + } |
| 29 | + |
| 30 | + .slide { |
| 31 | + width: var(--width); |
| 32 | + user-select: none; |
| 33 | + |
| 34 | + img { |
| 35 | + width: 100%; |
| 36 | + height: 100%; |
| 37 | + object-fit: cover; |
| 38 | + background-size: cover; |
| 39 | + background-position: center; |
| 40 | + background-repeat: no-repeat; |
| 41 | + transition: all 1s ease; |
| 42 | + overflow: hidden; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + .prev-arrows, |
| 47 | + .next-arrows { |
| 48 | + label { |
| 49 | + &::before { |
| 50 | + color: #aaa; |
| 51 | + font-size: 30px; |
| 52 | + position: absolute; |
| 53 | + top: 50%; |
| 54 | + margin-top: -10px; |
| 55 | + height: 20px; |
| 56 | + width: 20px; |
| 57 | + text-align: center; |
| 58 | + line-height: 15px; |
| 59 | + z-index: 1; |
| 60 | + cursor: pointer; |
| 61 | + } |
| 62 | + |
| 63 | + &:hover::before { |
| 64 | + color: #888; |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + .prev-arrows label::before { |
| 70 | + content: "❮"; |
| 71 | + left: -30px; |
| 72 | + } |
| 73 | + |
| 74 | + .next-arrows label { |
| 75 | + &::before { |
| 76 | + content: "❯"; |
| 77 | + right: -30px; |
| 78 | + } |
| 79 | + |
| 80 | + &:first-of-type { |
| 81 | + &::before { |
| 82 | + z-index: 2; |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + input:checked { |
| 88 | + ~ .slides-wrapper .slides { |
| 89 | + transform: translateX(calc(var(--width) * (1 - var(--selected-slide)))); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + @for $i from 1 through 20 { |
| 94 | + input:nth-of-type(#{$i}) { |
| 95 | + ~ * { |
| 96 | + --slides-number: #{$i}; |
| 97 | + } |
| 98 | + |
| 99 | + &:checked { |
| 100 | + ~ .slides-wrapper { |
| 101 | + --selected-slide: #{$i}; |
| 102 | + } |
| 103 | + |
| 104 | + ~ .prev-arrows { |
| 105 | + label:nth-of-type(#{$i - 1})::before { |
| 106 | + z-index: 2; |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + ~ .next-arrows { |
| 111 | + label:nth-of-type(#{$i + 1})::before { |
| 112 | + z-index: 2; |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + ~ .tracks label:nth-of-type(#{$i}) { |
| 117 | + &::after { |
| 118 | + transform: translate(-50%, -50%) scale(1, 1); |
| 119 | + opacity: 1; |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + .tracks { |
| 127 | + position: absolute; |
| 128 | + bottom: 8px; |
| 129 | + left: 0; |
| 130 | + width: 100%; |
| 131 | + height: 20px; |
| 132 | + display: flex; |
| 133 | + align-items: center; |
| 134 | + justify-content: center; |
| 135 | + z-index: 1; |
| 136 | + opacity: 0.9; |
| 137 | + |
| 138 | + label { |
| 139 | + position: relative; |
| 140 | + display: inline-block; |
| 141 | + width: 12px; |
| 142 | + height: 12px; |
| 143 | + border-radius: 50%; |
| 144 | + border: 2px solid #fff; |
| 145 | + box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3); |
| 146 | + margin-right: 6px; |
| 147 | + cursor: pointer; |
| 148 | + transition: opacity 0.2s; |
| 149 | + |
| 150 | + &:last-child { |
| 151 | + margin-right: 0; |
| 152 | + } |
| 153 | + |
| 154 | + &:hover { |
| 155 | + opacity: 0.8; |
| 156 | + } |
| 157 | + |
| 158 | + &::after { |
| 159 | + content: ""; |
| 160 | + position: absolute; |
| 161 | + top: 50%; |
| 162 | + left: 50%; |
| 163 | + transform: translate(-50%, -50%) scale(0, 0); |
| 164 | + width: 75%; |
| 165 | + height: 75%; |
| 166 | + border-radius: 50%; |
| 167 | + background-color: #fff; |
| 168 | + opacity: 0; |
| 169 | + transition: transform 0.3s; |
| 170 | + } |
| 171 | + // width: 8px; |
| 172 | + // height: 8px; |
| 173 | + // border: solid 1px #fff; |
| 174 | + // border-radius: 50%; |
| 175 | + // margin: 0 2px; |
| 176 | + // cursor: pointer; |
| 177 | + // box-shadow: 0 0 1px #aaa; |
| 178 | + } |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +@keyframes cssonlySlider { |
| 183 | + 0% { |
| 184 | + transform: translateX(0); |
| 185 | + } |
| 186 | + |
| 187 | + 25% { |
| 188 | + transform: translateX(calc(var(--width) * -1)); |
| 189 | + } |
| 190 | + |
| 191 | + 50% { |
| 192 | + transform: translateX(calc(var(--width) * -2)); |
| 193 | + } |
| 194 | + |
| 195 | + 75% { |
| 196 | + transform: translateX(calc(var(--width) * -3)); |
| 197 | + } |
| 198 | +} |
0 commit comments