Created
August 10, 2023 23:07
-
-
Save pejalo/64cdf74f143c66e3d9810546777167ee to your computer and use it in GitHub Desktop.
Simple loading component showing " ..", ". .", ".. ", repeated every second
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Note: This is a waste of JavaScipt resources, and will not update nicely | |
// if you are running heavy computations. Better to use an SVG or CSS. | |
import { onMount } from "svelte" | |
const fullString = "..." | |
let currentString = "" | |
onMount(() => { | |
let i = 0 | |
const numberOfSteps = fullString.length | |
const interval = setInterval(() => { | |
i = (i + 1) % numberOfSteps | |
currentString = fullString.substring(0, i) + " " + fullString.substring(i + 1) | |
}, 1000/numberOfSteps) | |
return () => { | |
clearInterval(interval) | |
} | |
}) | |
</script> | |
<span class="loading">{@html currentString}</span> | |
<style> | |
.loading { | |
font-family: monospace; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment