Amazing!!CSS 也能实现烟雾效果?
SegmentFault
共 5632字,需浏览 12分钟
·
2022-01-02 15:01
作者:chokcoco
来源:SegmentFault 思否社区
最近利用 CSS 实现了一些看似超出 CSS 能力的效果:
巧用渐变实现高级感拉满的背景光动画 https://github.com/chokcoco/iCSS/issues/150 Amazing!!CSS 也能实现极光? https://github.com/chokcoco/iCSS/issues/155
模糊效果 颗粒感
纯 CSS 实现烟雾动画
<span>C</span>
span {
text-shadow: 0 0 0 whitesmoke;
animation: smoky 5s;
}
@keyframes smoky {
to {
text-shadow: 0 0 20px whitesmoke;
opacity: 0;
}
}
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;
}
}
<div>
<span>C</span>
<span>S</span>
<span>S</span>
// ...
</div>
// ... 上述所有 CSS 代码
@for $item from 1 through 21 {
span:nth-of-type(#{$item}){
animation-delay: #{(($item/10))}s;
}
}
借助 SVG feturbulence 滤镜实现烟雾效果
有意思!强大的 SVG 滤镜 https://github.com/chokcoco/cnblogsArticle/issues/27 震惊!巧用 SVG 滤镜还能制作表情包? https://github.com/chokcoco/iCSS/issues/107 实现一个会动的鸿蒙 LOGO https://github.com/chokcoco/iCSS/issues/137
<div">SMOKE</div>
div {
background: linear-gradient(#fff, #999, #ddd, #888);
background-clip: text;
}
<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>
body {
filter: url('#filter');
}
div {
background: linear-gradient(#fff, #999, #ddd, #888);
background-clip: text;
}
body {
filter: url('#filter');
}
div {
background: linear-gradient(#fff, #999, #ddd, #888);
background-clip: text;
filter: blur(5px);
}
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);
控制 <feTurbulence> 的 baseFrequency 属性调节 控制 <feTurbulence> 的 numOctaves 属性调节 控制 <feDisplacementMap> 的 scale 属性调节
最后
评论