1. 實現(xiàn)波浪背景
div{ width: 400px; height: 200px; outline: 2px dashed gray; --c: #2196F3; --w1: radial-gradient(100% 57% at top ,#0000 100%,var(--c) 100.5%) no-repeat; --w2: radial-gradient(100% 57% at bottom, var(--c) 100%,#0000 100.5%) no-repeat; background: var(--w1),var(--w2),var(--w1),var(--w2); background-position-x: -200%, -100%, 0%, 100%; background-position-y: 100%; background-size: 50.5% 100%; animation: m 1s infinite linear; } @keyframes m { 0% {background-position-x:-200%, -100%, 0%, 100%} 100%{background-position-x: 0%, 100%, 200%, 300%} }
原理:透明到純色的徑向漸變,然后復(fù)制該漸變背景,最后加上背景水平方向移動的無限循環(huán)動畫
2. 文字波浪背景
將該漸變應(yīng)用在文本標(biāo)簽上,并添加一下css屬性
{ font-size: 100px; font-weight: bold; color: transparent; -webkit-background-clip: text; /*文本裁切*/ -webkit-text-stroke: 2px var(--c); /*文本內(nèi)描邊*/ }
最后,在做一些適當(dāng)調(diào)整,比如弧度銜接處 動畫時間等 。搞定
3. 總結(jié)文章來源:http://www.zghlxwxcb.cn/news/detail-475449.html
- 波浪的本質(zhì)上是一個曲面在水平方向的周期性運動,曲面本身并沒有變化
- 波浪可以拆分為兩個不同方向上的徑向漸變
- 特別需要注意漸變的尺寸和位置,確保能夠完美的銜接在一起
- 動畫其實就是不斷改變漸變的水平位置,也就是?
background-position-x
- 相比于其他實現(xiàn),漸變的最大優(yōu)勢是不占用任何標(biāo)簽
- 還可以輕易的實現(xiàn)文字波浪效果
注:文章來源于前端偵探?,作者XboxYan,《這個文字波浪動畫,真酷!》文章來源地址http://www.zghlxwxcb.cn/news/detail-475449.html
到了這里,關(guān)于文字效果 用背景漸變實現(xiàn) 波浪背景文字的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!