|
20 | 20 | * Карточки |
21 | 21 | * @type {HTMLElement[]} |
22 | 22 | */ |
23 | | - let cards; |
| 23 | + let cards = $state([]); |
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * Количество видимых карточек |
27 | 27 | * @type {number} |
28 | 28 | */ |
29 | | - let shownCardsNumber; |
| 29 | + let shownCardsNumber = $state(1); |
30 | 30 |
|
31 | 31 | /** |
32 | 32 | * Начальная координата свайпа |
|
161 | 161 | cardsSwiper.classList.remove('welcome-animation'); |
162 | 162 | isSwipeIgnored = false; |
163 | 163 | }, 2000); |
164 | | - cards = document.querySelectorAll('.cards-swiper > *'); |
| 164 | + cards = document.querySelectorAll('.cards-swiper > .card'); |
165 | 165 | cards[0].classList.add('shown'); |
166 | 166 | shownCardsNumber = 1; |
167 | 167 | }); |
|
177 | 177 | </script> |
178 | 178 |
|
179 | 179 | <div |
180 | | - class="md:hidden relative w-full h-[310px] cards-swiper perspective-[200px]" |
| 180 | + class="md:hidden relative w-full h-[310px] cards-swiper" |
181 | 181 | ontouchstart={onTouchStart} |
182 | 182 | ontouchend={onTouchEnd} |
183 | 183 | > |
184 | 184 | {@render children?.()} |
| 185 | + <span class="absolute top-full left-1/2 -translate-x-1/2 text-sm counter"> |
| 186 | + {shownCardsNumber}/{cards.length} |
| 187 | + </span> |
185 | 188 | </div> |
186 | 189 |
|
187 | 190 | <style> |
|
194 | 197 |
|
195 | 198 | @keyframes cardAnimation { |
196 | 199 | 0% { |
197 | | - transform: translateY(var(--initial-translate, 0)) scale(1) rotateX(0deg); |
| 200 | + transform: translateY(var(--initial-translate, 0)) scale(var(--initial-scale, 1)); |
198 | 201 | } |
199 | 202 | 50% { |
200 | | - transform: |
201 | | - translateY(var(--intermediate-translate, 0)) |
202 | | - scale(var(--intermediate-scale, 1)) |
203 | | - rotateX(var(--intermediate-rotation, 0deg)); |
| 203 | + transform: translateY(var(--intermediate-translate, 0)) scale(var(--intermediate-scale, 1)); |
204 | 204 | } |
205 | 205 | 100% { |
206 | | - transform: translateY(var(--initial-translate, 0)) scale(1) rotateX(0deg); |
| 206 | + transform: translateY(var(--initial-translate, 0)) scale(var(--initial-scale, 1)); |
207 | 207 | } |
208 | 208 | } |
209 | 209 |
|
210 | | - .cards-swiper:global(.welcome-animation > *) { |
211 | | - --intermediate-scale: 0.9; |
212 | | - --intermediate-rotation: -7deg; |
| 210 | + .cards-swiper:global(.welcome-animation > .counter) { |
| 211 | + @apply hidden; |
| 212 | + } |
| 213 | +
|
| 214 | + .cards-swiper:global(.welcome-animation > .card) { |
213 | 215 | animation: 2s cardAnimation; |
214 | 216 | } |
215 | 217 |
|
216 | | - .cards-swiper:global(.welcome-animation > *:nth-child(n+2)) { |
217 | | - /* .shadow-sm, но вверх, а не вниз */ |
218 | | - box-shadow: 0 -1px 2px 0 rgb(0 0 0 / 0.05); |
219 | | - --initial-translate: 10%; |
220 | | - --intermediate-translate: calc(-30% + var(--index) * 20px); |
| 218 | + .cards-swiper:global(.welcome-animation > .card:nth-child(1)) { |
| 219 | + --initial-translate: -100%; |
| 220 | + --intermediate-translate: -100%; |
| 221 | + --intermediate-scale: 0.9; |
221 | 222 | } |
222 | 223 |
|
223 | | - :global(html[data-theme="dark"] .cards-swiper.welcome-animation > *:nth-child(n+2)) { |
224 | | - box-shadow: 0 -1px 2px 0 rgb(200 200 200 / 0.05); |
| 224 | + .cards-swiper:global(.welcome-animation > .card:nth-child(n+2)) { |
| 225 | + --intermediate-translate: calc(-30% + var(--index) * 20px); |
| 226 | + --initial-scale: 1.1; |
225 | 227 | } |
226 | 228 |
|
227 | | - .cards-swiper:global(.welcome-animation > *:nth-child(2)) { |
| 229 | + .cards-swiper:global(.welcome-animation > .card:nth-child(2)) { |
228 | 230 | --index: 0; |
229 | 231 | } |
230 | 232 |
|
231 | | - .cards-swiper:global(.welcome-animation > *:nth-child(3)) { |
| 233 | + .cards-swiper:global(.welcome-animation > .card:nth-child(3)) { |
232 | 234 | --index: 1; |
233 | 235 | } |
234 | 236 |
|
235 | | - .cards-swiper > :global(*) { |
| 237 | + .cards-swiper > :global(.card) { |
236 | 238 | @apply absolute; |
237 | 239 | @apply top-full; |
238 | 240 | @apply h-full; |
239 | 241 | @apply transition-all; |
240 | | - transform: translateY(0) scaleX(0) rotateX(-52.2245deg); |
| 242 | + transform: translateY(0) scale(1.1); |
241 | 243 | transition-property: transform, top; |
242 | 244 | transition-duration: 375ms; |
243 | 245 | /* timig function из tailwind .transition-all */ |
244 | 246 | animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); |
245 | 247 | } |
246 | 248 |
|
247 | | - .cards-swiper > :global(.shown) { |
248 | | - --initial-translate: -100%; |
249 | | - --intermediate-translate: -100%; |
250 | | - transform: translateY(-100%) scale(1) rotateX(0deg); |
| 249 | + .cards-swiper > :global(.card.shown) { |
| 250 | + transform: translateY(-100%) scale(0.9); |
251 | 251 | } |
252 | 252 |
|
253 | | - .cards-swiper:global(.swiped-up > *:nth-last-child(n + 2 of .shown)) { |
254 | | - --intermediate-scale: 0.9; |
255 | | - --intermediate-rotation: -7deg; |
256 | | - animation: 375ms cardAnimation; |
| 253 | + .cards-swiper > :global(.card:nth-last-child(1 of .shown)) { |
| 254 | + transform: translateY(-100%) scale(1); |
257 | 255 | } |
258 | 256 |
|
259 | | - .cards-swiper:global(.swiped-down > .shown) { |
260 | | - --intermediate-scale: 0.9; |
261 | | - --intermediate-rotation: -7deg; |
262 | | - animation: 375ms cardAnimation; |
| 257 | + .cards-swiper > :global(.card:not(.shown)) { |
| 258 | + top: calc(100% + 32px); |
| 259 | + } |
| 260 | +
|
| 261 | + .cards-swiper > :global(.card:nth-child(1 of .card:not(.shown))) { |
| 262 | + @apply top-full; |
| 263 | + @apply shadow-md-upside; |
| 264 | + } |
| 265 | +
|
| 266 | + .cards-swiper > :global(.card:nth-child(2 of .card:not(.shown))), |
| 267 | + .cards-swiper > :global( |
| 268 | + .card:nth-child(1 of .card:not(.shown)):nth-last-child(1 of .card:not(.shown)) |
| 269 | + ) { |
| 270 | + @apply shadow-md-upside; |
| 271 | + top: calc(100% + 10px); |
263 | 272 | } |
264 | 273 |
|
265 | | - .cards-swiper:global(.overswiped-up > .shown) { |
| 274 | + .cards-swiper:global(.overswiped-up > .card.shown) { |
| 275 | + --initial-translate: -100%; |
266 | 276 | --intermediate-translate: calc(-100% - 20px); |
267 | 277 | animation: 375ms cardAnimation; |
268 | 278 | } |
269 | 279 |
|
270 | | - .cards-swiper:global(.overswiped-down > .shown) { |
| 280 | + .cards-swiper:global(.overswiped-down > .card.shown) { |
| 281 | + --initial-translate: -100%; |
271 | 282 | --intermediate-translate: calc(-100% + 20px); |
272 | 283 | animation: 375ms cardAnimation; |
273 | 284 | } |
|
0 commit comments