<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>
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ... </head>
<body>
</body>
CSS
格式化
body, html {
width: 100%;
height: 100%;
display: flex;
background: #000;
}
body {
filter: url('#filter');
}
div {
width: 120vh;
height: 80vh;
margin: auto;
background: linear-gradient(#fff, #999, #ddd, #888);
background-clip: text;
color: transparent;
font-size: 30vmin;
text-align: center;
line-height: 80vh;
filter: blur(6px) contrast(120%);
}
JS
格式化
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);