svg效果之文字贴合纹理
效果如下,文字随着背景明暗变化
1 2 3 4 5 6 7 8 9 10 11 12 | <svg viewBox= "0 0 660 300" > <defs> <filter id= "comform" > <feImage :href= "image1" x= "0" y= "0" width= "100%" height= "100%" preserveAspectRatio= "none" result= "ORIGIN_IMAGE" ></feImage> <feColorMatrix type= "matrix" values= "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0.9 0" in = "ORIGIN_IMAGE" result= "GRAY_IMAGE" ></feColorMatrix> <feDisplacementMap in = "SourceGraphic" in2= "GRAY_IMAGE" scale= "15" xChannelSelector= "R" yChannelSelector= "R" result= "TEXTURED_TEXT" ></feDisplacementMap> <feBlend in = "BG" in2= "OPACITY_TEXT" MODE= "multiply" result= "BLENDED_TEXT" ></feBlend> </filter> </defs> <image href= "../../assets/moon.png" x= "0" y= "0" width= "100%" height= "100%" preserveAspectRatio= "none" ></image> <text width= "50%" height= "50%" x= "60" y= "120" font-size= "5em" font-weight= "bold" text-anchor= "left" fill= "#000" :filter= "`url(#comform)`" >文字贴合背景</text> </svg> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <script lang= "ts" > import { ref } from 'vue' ; import { ElMessage } from 'element-plus' ; import image1 from '/@/assets/moon.png' ; export default { setup() { const back = () => { window.history.back(); }; return { back, image1, }; }, }; </script> |
代码地址:https://gitee.com/yuexiayunsheng/vue3learn/blob/master/src/views/cssEffect/TextFitsBackground.vue
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)