Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use CSS to achieve auroral effect

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use CSS to achieve the aurora effect, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Like this:

Emmm, this is a little awkward. However, recently I also tried to try, although it is impossible to simulate such a real effect, but using CSS can still make some similar special effects, today we will try it together.

After observing some pictures of the aurora, I found some of the more important elements in the aurora animation:

Bright gradient color based on dark background

Similar to the animation effect of water wave flow

Bright gradient colors we can try to use gradient simulation. As for the animation effect of water wave flow, this is what feturbulence does in the SVG filter, and the use of this filter has been mentioned repeatedly in my past articles.

In addition to gradients and SVG filters, we may also use mixed mode (mix-blend-mode), CSS filters and other enhancement effects.

OK, after you have a general idea, all that's left is to keep trying.

Step 1. Draw a dark background

First of all, we may need a dark background to represent our night sky. At the same time, dotted with some stars, the stars can be simulated using box-shadow, so that we can complete a night sky background in 1 p:

@ function randomNum ($max, $min: 0, $u: 1) {@ return ($min + random ($max)) * $u;} @ function shadowSet ($n, $size) {$shadow: 00 # fff; @ for $I from 0 through $n {$x: randomNum; $y: randomNum (500); $scale: randomNum ($size) / 10 $shadow: $shadow, # {$x} px # {$y} px 0 # {$scale} px rgba (255,255,255, .8);} @ return $shadow;}. G-wrap {position: relative; width: 350px; height: 500px; background: # 0b1a3a; overflow: hidden; &: before {content: "; position: absolute; width: 1px Height: 1px; border-radius: 50%; box-shadow: shadowSet (100,6);}

This step is relatively simple. With the help of SASS, we can get a background picture of the night sky like this:

Step 2. Use a gradient to outline the aurora

The next step is to use the gradient to draw an outline of the aurora.

It's actually a radial gradient:

. g-aurora {width: 400px; height: 300px; background: radial-gradient (circle at 100% 100%, transparent 45%, # bd63c1 55%, # 53e5a6 65%, transparent 85%);}

Step 3. Rotational stretch

At present, it seems that there is a little outline. Next, we transform the gradient effect by rotating and stretching.

. g-aurora {... Transform: rotate (45deg) scaleX

We can probably get this effect:

Step 4. Magical mixed mode transformation!

At this point, in fact, the prototype has already come out. But the color doesn't look like it. In order to blend with the dark background, we use the mixed mode mix-blend-mode here.

. g-aurora {... Transform: rotate (45deg) scaleX; mix-blend-mode: color-dodge;}

Something amazing happened. Look at the effect:

The overall color looks more like the color of the aurora.

Step 5. Overlay SVG feturbulence filter

Next, if we want to produce the effect of water ripple, we need to use the filter of SVG. For those who don't know much about this filter, you can take a look at these articles:

Interesting! Powerful SVG filter

A great shock! Can you make memes with SVG filters skillfully?

Realize a moving Hongmeng LOGO

Let's get back to business. Let's add a filter for SVG and use CSS filter for reference

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report