概述

最近在刷抖音时,看到了某位大佬发的vue实现满天星动态效果,感觉不错,顺便照做写在了我的demo上。

实现效果

在这里插入图片描述

实现

HTML

<template>
   <div  class="star">
      <div class="dot" v-for="item in nums" :key="item" :style="`--delay:${Math.random() * 2}s;--color:hsl(${Math.random() * 360},50%,50%)`">
		</div>
	</div>	
</template>

JS

<script setup lang="ts">
import { ref, computed } from 'vue'
const nums = computed(()=>{
	return Math.floor(window.innerWidth / 10)
})
</script>

CSS

<style lang="scss" scoped>

.star {
	width: 100%;
	height: 100vh;
	overflow: hidden;
	background: #000;
	display: flex;
	justify-content: space-between;
	align-items: flex-end;
}
.dot {
	width: 5px;
	height: 5px;
	background-color: var(--color);
	border-radius: 50%;
	animation: up 2s ease-in infinite;
	animation-delay: var(--delay);
	z-index:1;
}

@keyframes up {
	to {
		transform: translateY(-100vh);
	}
}
</style>
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐