diff --git a/docs/src/components/spark-ui/meteors/Meteors.vue b/docs/src/components/spark-ui/meteors/Meteors.vue index 93b9457..59170d3 100644 --- a/docs/src/components/spark-ui/meteors/Meteors.vue +++ b/docs/src/components/spark-ui/meteors/Meteors.vue @@ -12,16 +12,19 @@ const props = withDefaults(defineProps(), { const meteorStyles = ref() +const getRandomPosition = (max: number) => `${Math.floor(Math.random() * max)}px` +const getRandomDelay = () => `${(Math.random() * 1 + 0.2).toFixed(2)}s` +const getRandomDuration = () => `${Math.floor(Math.random() * 8 + 2)}s` + watch(() => props.number, (val) => { - const styles = [...Array.of(val)].map(() => ({ + const styles = Array.from({ length: val }, () => ({ top: -5, - left: `${Math.floor(Math.random() * window.innerWidth)}px`, - animationDelay: `${Math.random() * 1 + 0.2}s`, - animationDuration: `${Math.floor(Math.random() * 8 + 2)}s`, + left: getRandomPosition(window.innerWidth), + animationDelay: getRandomDelay(), + animationDuration: getRandomDuration(), })) meteorStyles.value = styles }, { - deep: true, immediate: true, }) diff --git a/docs/src/example/meteors/Meteors.vue b/docs/src/example/meteors/Meteors.vue index 9898050..9ab64c2 100644 --- a/docs/src/example/meteors/Meteors.vue +++ b/docs/src/example/meteors/Meteors.vue @@ -12,16 +12,19 @@ const props = withDefaults(defineProps(), { const meteorStyles = ref() +const getRandomPosition = (max: number) => `${Math.floor(Math.random() * max)}px` +const getRandomDelay = () => `${(Math.random() * 1 + 0.2).toFixed(2)}s` +const getRandomDuration = () => `${Math.floor(Math.random() * 8 + 2)}s` + watch(() => props.number, (val) => { - const styles = [...Array.of(val)].map(() => ({ + const styles = Array.from({ length: val }, () => ({ top: -5, - left: `${Math.floor(Math.random() * window.innerWidth)}px`, - animationDelay: `${Math.random() * 1 + 0.2}s`, - animationDuration: `${Math.floor(Math.random() * 8 + 2)}s`, + left: getRandomPosition(window.innerWidth), + animationDelay: getRandomDelay(), + animationDuration: getRandomDuration(), })) meteorStyles.value = styles }, { - deep: true, immediate: true, }) @@ -50,6 +53,7 @@ watch(() => props.number, (val) => { 70% { opacity: 1; } + 100% { transform: rotate(215deg) translateX(-500px); opacity: 0;