Carousel: Add a transition on title when changing photo

This commit is contained in:
2020-02-26 15:58:22 +01:00
parent 17c1e3e930
commit fab89736ed
3 changed files with 62 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
<script> <script>
import { onMount } from 'svelte' import { onMount } from 'svelte'
import { fly } from 'svelte/transition'
import { currentLocation } from '../store'
import * as fn from '../functions' import * as fn from '../functions'
// Dependencies // Dependencies
@@ -152,16 +154,27 @@
</div> </div>
{#if viewer} {#if viewer}
<div class="carousel__number">{currentIndex < 10 ? 0 : ''}{currentIndex + 1}</div> <div class="carousel__number">
{currentIndex < 10 ? 0 : ''}{photos.length - currentIndex}
</div>
{/if} {/if}
</div> </div>
<div class="carousel__information"> <div class="carousel__information">
<div class="carousel__information--location style-location"> <div class="carousel__information--location style-location">
<p class="street">{currentPhoto.name}</p> <p class="street">
<p class="style-caps state">{currentPhoto.location.region}, {currentPhoto.location.country.name}</p> {#each photos as photo, index}
<span aria-hidden={photo !== currentPhoto}
class:prev={photo === prevPhoto}
class:active={photo === currentPhoto}
class:next={photo === nextPhoto}>
{photo.name}
</span>
{/each}
</p>
<p class="state style-caps style-caps--transparent">Add the state!!!</p>
<!-- <p class="state style-caps style-caps--transparent">{photo.location.region}, {photo.location.country.name}</p> -->
</div> </div>
<!-- Duplicate for animation? -->
{#if viewer} {#if viewer}
<p class="carousel__information--date">{dayjs(currentPhoto.created_on).format('MMM Do, YYYY')}</p> <p class="carousel__information--date">{dayjs(currentPhoto.created_on).format('MMM Do, YYYY')}</p>
{/if} {/if}

View File

@@ -44,6 +44,8 @@
// Photo // Photo
&--photo { &--photo {
$duration: 0.9s;
opacity: 0; opacity: 0;
overflow: hidden; overflow: hidden;
position: absolute; position: absolute;
@@ -54,7 +56,7 @@
height: 100%; height: 100%;
transform: scale($scale); transform: scale($scale);
box-shadow: 0 pxVW(15) pxVW(60) rgba(#000, 0.3); box-shadow: 0 pxVW(15) pxVW(60) rgba(#000, 0.3);
transition: transform 600ms $ease-quart, opacity 600ms $ease-quart; transition: transform $duration $ease-quart, opacity $duration $ease-quart;
will-change: transform, opacity; will-change: transform, opacity;
@include breakpoint (sm) { @include breakpoint (sm) {
@@ -179,16 +181,23 @@
} }
} }
// Information
/*
** Information
*/
&__information { &__information {
position: relative; position: relative;
z-index: 3; z-index: 3;
// Location // Location
&--location { &--location {
text-align: center;
.street { .street {
margin-top: 24px; width: 100%;
color: #fff; position: relative;
margin-top: 32px;
height: 30px;
@include breakpoint (sm) { @include breakpoint (sm) {
margin-top: pxVW(80); margin-top: pxVW(80);
@@ -196,16 +205,43 @@
@include breakpoint (xl) { @include breakpoint (xl) {
margin-top: 72px; margin-top: 72px;
} }
span {
$distance: 40%;
position: absolute;
display: block;
top: 0;
left: 0;
width: 100%;
white-space: nowrap;
transform: translateY(-$distance);
opacity: 0;
transition: transform 0.9s $ease-quart, opacity 0.9s $ease-quart;
will-change: transform, opacity;
&.prev {
transform: translateY(-$distance);
}
&.active {
transform: translateY(0);
opacity: 1;
}
&.next {
transform: translateY($distance);
}
}
} }
.state { .state {
margin-top: 4px; margin-top: 6px;
color: rgba($color-tertiary, 0.5);
} }
} }
} }
// Dots for slider (mobile) /*
** Dots for slider (mobile)
*/
&__dots { &__dots {
display: none; display: none;

View File

@@ -96,7 +96,7 @@
// Information // Information
&__information { &__information {
margin-top: 24px; margin-top: 32px;
padding: 0 24px; padding: 0 24px;
@include breakpoint (sm) { @include breakpoint (sm) {
@@ -107,6 +107,7 @@
// Location // Location
&--location { &--location {
width: 75%;
text-align: left; text-align: left;
.street { .street {