#54 : Use CSS animations for dot size

This commit is contained in:
Vadim
2021-08-08 13:58:00 +03:00
parent bf75a468e6
commit 993f2f2ffb
2 changed files with 18 additions and 23 deletions

View File

@@ -1,33 +1,14 @@
<script> <script>
import { tweened } from 'svelte/motion';
import { cubicInOut } from 'svelte/easing';
const DOT_SIZE_PX = 5
const ACTIVE_DOT_SIZE_PX = 8
const size = tweened(DOT_SIZE_PX, {
duration: 250,
easing: cubicInOut
});
/** /**
* Indicates if dot is active * Indicates if dot is active
*/ */
export let active = false export let active = false
$: {
size.set(active ? ACTIVE_DOT_SIZE_PX : DOT_SIZE_PX)
}
</script> </script>
<div class="sc-carousel-dot__container"> <div class="sc-carousel-dot__container">
<div <div
class="sc-carousel-dot__dot" class="sc-carousel-dot__dot"
class:sc-carousel-dot__dot_active={active} class:sc-carousel-dot__dot_active={active}
style="
height: {$size}px;
width: {$size}px;
"
on:click on:click
></div> ></div>
</div> </div>
@@ -39,20 +20,33 @@
justify-content: center; justify-content: center;
height: 16px; height: 16px;
width: 16px; width: 16px;
:root {
--sc-dot-size: 6px;
--sc-active-dot-size: 8px;
--sc-dot-size-animation-time: 250ms;
} }
.sc-carousel-dot__dot { .sc-carousel-dot__dot {
background-color: var(--sc-color-rgb-light); background-color: var(--sc-color-rgb-light);
border-radius: 50%; border-radius: 50%;
display: inline-block; display: inline-block;
opacity: 0.5; opacity: 0.5;
transition: opacity 100ms ease; transition:
opacity 100ms ease,
height var(--sc-dot-size-animation-time) ease,
width var(--sc-dot-size-animation-time) ease;
cursor: pointer; cursor: pointer;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
height: var(--sc-dot-size);
width: var(--sc-dot-size);
} }
.sc-carousel-dot__dot:hover { .sc-carousel-dot__dot:hover {
opacity: 0.9; opacity: 0.9;
} }
.sc-carousel-dot__dot_active { .sc-carousel-dot__dot_active {
opacity: 0.7; opacity: 0.7;
height: var(--sc-active-dot-size);
width: var(--sc-active-dot-size);
} }
</style> </style>

View File

@@ -32,8 +32,9 @@
<style> <style>
:root { :root {
--sc-dot-size: 10px; --sc-dot-container-size: 10px;
} }
.sc-carousel-dots__container { .sc-carousel-dots__container {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -42,8 +43,8 @@
padding: 0 30px; padding: 0 30px;
} }
.sc-carousel-dots__dot-container { .sc-carousel-dots__dot-container {
height: calc(var(--sc-dot-size) + 10px); height: calc(var(--sc-dot-container-size) + 10px);
width: calc(var(--sc-dot-size) + 6px); width: calc(var(--sc-dot-container-size) + 6px);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;