Teach you how to use css to achieve smoke effects in ten minutes
This article will share with you how to use css to achieve the smoke effect. I hope it will be helpful to everyone.
Look closely at the smoke effect, there are two important features:
Blur effect
Grainy feeling
First look at the blur effect. When thinking of blur, most students will first think of using filter: blur().
Of course that’s true, but in CSS, in addition to filters, we can also use a type of other means to simulate the blurring effect.
Pure CSS to implement smoke animation
Let’s first look at such an effect:
Suppose we have such a character:
<span>C</span>
We can simulate the effect of smoke just by changing the text-shadow opacity:
span { text-shadow: 0 0 0 whitesmoke; animation: smoky 5s; } @keyframes smoky { to { text-shadow: 0 0 20px whitesmoke; opacity: 0; } }
Based on the above, we can Add displacement, rotation, and scaling, slightly modify the above code, and add some transform transformations:
span { text-shadow: 0 0 0 whitesmoke; animation: smoky 5s; } @keyframes smoky { to { transform: translate3d(200px, -80px, 0) rotate(-40deg) skewX(70deg) scale(1.5); text-shadow: 0 0 20px whitesmoke; opacity: 0; } }
to get the following effect:
superimposed transform After that, it felt like a word was blown away and turned into smoke. On this basis, we only need to put multiple words together and use animation-delay to sequentially control each word to trigger the animation effect to get the complete smoke effect mentioned above.
The pseudo code is as follows:
<span>C</span> S S // ...
// ... 上述所有 CSS 代码 @for $item from 1 through 21 { span:nth-of-type(#{$item}){ animation-delay: #{(($item/10))}s; } }
Use the SVG feturbulence filter to achieve the smoke effect
The smoke of the above smoke animation is still the same Relatively rough. Mainly because it lacks a bit of graininess? Some of the smoke texture is missing.
To achieve a more refined smoke effect, we have to use SVG's
Next, we will use filter: blur() with the
For a simple example, suppose there are several words like this:
<div">SMOKE</div>
Simple CSS:
div { background: linear-gradient(#fff, #999, #ddd, #888); background-clip: text; }
Get several words with gradient colors like this:
We use the
<div>SMOKE</div> <svg width="0"> <filter id="filter"> <feTurbulence id="turbulence" type="fractalNoise" baseFrequency=".03" numOctaves="20" /> <feDisplacementMap in="SourceGraphic" scale="30" /> </filter> </svg>
Use filter: url() in CSS to introduce this filter. In order to achieve better results here, I introduced this filter directly on the
:body { filter: url('#filter'); } div { background: linear-gradient(#fff, #999, #ddd, #888); background-clip: text; }
Our font is given a fluid feel by the
This effect can be said to have basically nothing to do with the smoke effect, but you only need to add a blur filter, and something magical will happen:
body { filter: url('#filter'); } div { background: linear-gradient(#fff, #999, #ddd, #888); background-clip: text; filter: blur(5px); }
The entire effect will instantly become smoky:
Okay, add a looping animation effect to it, and simply use JavaScript to process it:
const filter = document.querySelector("#turbulence"); let frames = 1; let rad = Math.PI / 180; let bfx, bfy; function freqAnimation() { frames += .2 bfx = 0.03; bfy = 0.03; bfx += 0.005 * Math.cos(frames * rad); bfy += 0.005 * Math.sin(frames * rad); bf = bfx.toString() + " " + bfy.toString(); filter.setAttributeNS(null, "baseFrequency", bf); window.requestAnimationFrame(freqAnimation); } window.requestAnimationFrame(freqAnimation);
Look at the effect:
Of course, the above effects can be achieved by:
Control the baseFrequency attribute adjustment of
Control the numOctaves attribute adjustment of
Control the scale attribute adjustment of
Change the numOctaves attribute of
css video tutorial)
The above is the detailed content of Teach you how to use css to achieve smoke effects in ten minutes. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
