欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > vue星空背景组件

vue星空背景组件

2025/7/7 19:06:09 来源:https://blog.csdn.net/HarryHY/article/details/145601647  浏览:    关键词:vue星空背景组件

组件

<template><div class="starlit_sky"><div class="layer1"></div><div class="layer2"></div><div class="layer3"></div><slot name="contentmain"></slot></div>
</template><script >
/*** 这是一个星空背景组件* 如果在使用时,需要使用插槽,则需要在插槽中添加teleport标签,并设置name属性为contentmain (v-slot:contentmain)*/
</script><style lang="scss" scoped>
@import url('./index.scss');
</style>

scss代码

.starlit_sky {width: 100vw;height: 100vh;background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);overflow: hidden;
}
.contentmain-style {position: absolute;width: 100vw;height: 100vh;left: 0;right: 0;
}
@function getShadows($n) {$shadows: '#{random(100)}vw #{random(100)}vh #fff';@for $i from 2 through $n {$shadows: '#{$shadows}, #{random(100)}vw #{random(100)}vh #fff';}@return unquote($shadows);
}
$duration: 400s;
$count: 1000;
@for $i from 1 through 3 {$duration: floor($duration/ 2);$count: floor($count/2);.layer#{$i} {$size: #{$i}px;position: fixed;width: $size;height: $size;border-radius: 50%;background: #fff;box-shadow: getShadows($count);animation: moveup $duration linear infinite;&::after {content: '';position: fixed;left: 0;top: 100vh;width: $size;height: $size;border-radius: inherit;box-shadow: inherit;}}
}@keyframes moveup {100% {transform: translateY(-100vh);}
}

父组件的调用

<template><StarlitSky><template v-slot:contentmain></template></StarlitSky>
</template><script setup>
import {defineAsyncComponent} from 'vue';
const StarlitSky = defineAsyncComponent(()=>import('../../components/starlitSky/index.vue'))
</script>
<style lang="less" scoped>
</style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词