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

posted @   月下云生  阅读(76)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示