点击查看html编辑器说明文档

SVG滤镜实现文字烟雾效果edit icon

|
|
Fork(复制)
|
|
提交反馈
嵌入
设置
下载
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ...
展开
</head>
<body>
            
            <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>
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);
        
预览
控制台