Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Starry Sky effect with Vue

Shulou Source: shulou.com Published: 2022-06-01 00:07:18 10月03日 Update

This article mainly explains "how to achieve the starry sky effect with Vue". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to achieve the starry sky effect with Vue".

The effect of starry sky is as follows

1. Star background sub-component

Export default {name: 'StarBackground', props: {}, data () {return {starsCount: 1200, distance: 800}}, mounted () {this.initStars ()} Methods: {initStars () {let starArr = this.$refs.star starArr.forEach (item = > {let speed = 0.2 + (Math.random () * 1) let thisDistance = this.distance + (Math.random () * 300) item.style.transformOrigin = `00 ${thisDistance} px` item.style.transform = `translate3d (0,0) -${thisDistance} px) rotateY (${(Math.random () * 360)} deg) rotateX (${(Math.random () *-50)} deg) scale (${speed}, ${speed}) `} @ keyframes rotate {0% {transform: perspective (600px) rotateZ (20deg) rotateX (- 40deg) rotateY (0) } 100% {transform: perspective (600px) rotateZ (20deg) rotateX (- 40deg) rotateY (- 360deg);}. Stars {transform: perspective (500px); transform-style: preserve-3d; position: absolute; perspective-origin: 50% 100%; left: 50%; animation: rotate 90s infinite linear; bottom:-200px;} .star {width: 2px; height: 2px; background: # f7f7b8; position: absolute; top: 0; left: 0; backface-visibility: }

two。 Login page reference subcomponent

Import StarBackground from'. / components/StarBackground'export default {beforeCreate: function () {document.getElementsByTagName ('body') [0] .className =' body-bg'}, components: {StarBackground}}. Body-bg {background-attachment: fixed; overflow: hidden;}. Login-container {height: 100%; width: 100%; overflow: hidden; background-color: # 050608;}

Background-attachment: fixed; is very important. You need to fix the interface, or else the drop-down will go blank.

At this point, I believe you have a deeper understanding of "how to achieve starry effect in Vue". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Starry sky effects content components learning practical deeper important interest practicality simple operation method more friends interface blank website background channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL Shulou Information Docker Linux