Amazing??!CSS 也能實現(xiàn)煙霧效果?
作者:chokcoco
來源:SegmentFault 思否社區(qū)
最近利用 CSS 實現(xiàn)了一些看似超出 CSS 能力的效果:
巧用漸變實現(xiàn)高級感拉滿的背景光動畫 https://github.com/chokcoco/iCSS/issues/150 Amazing??!CSS 也能實現(xiàn)極光? https://github.com/chokcoco/iCSS/issues/155

模糊效果 顆粒感
純 CSS 實現(xiàn)煙霧動畫

<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 濾鏡實現(xiàn)煙霧效果
有意思!強大的 SVG 濾鏡 https://github.com/chokcoco/cnblogsArticle/issues/27 震驚!巧用 SVG 濾鏡還能制作表情包? https://github.com/chokcoco/iCSS/issues/107 實現(xiàn)一個會動的鴻蒙 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 屬性調(diào)節(jié) 控制 <feTurbulence> 的 numOctaves 屬性調(diào)節(jié) 控制 <feDisplacementMap> 的 scale 屬性調(diào)節(jié)

最后

評論
圖片
表情
