主页 > 创业  > 

vue3背景虚化,文字高亮效果

vue3背景虚化,文字高亮效果

效果:

组件代码:

<template> <div :style="styleComputed" class="background-blurring"> <div class="mask"></div> <div :style="styleComputed" class="blurring-text">background</div> </div> </template> <script setup> import { computed } from "vue"; const props = defineProps({ url: String }); const styleComputed = computed(() => { return { backgroundImage: `url(${props.url})` }; }); </script> <style scoped> .background-blurring { background-repeat: no-repeat; width: 100%; height: 100%; font-size: 12vw; position: relative; } .background-blurring .blurring-text { width: 100%; height: 100%; -webkit-text-stroke: 2px #fff; display: flex; justify-content: center; align-items: center; position: absolute; left: 0; top: 0; background-clip: text; color: #0000; } .mask { width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); } </style>

使用代码:

<template> // 传入图片资源 <BackgroundBlurring :url="img"/> <template> <script setup> // 引入组件 import BackgroundBlurring from "./components/BackgroundBlurring.vue"; // 引入资源 import img from "@/assets/imgs/background.jpg"; </script>

标签:

vue3背景虚化,文字高亮效果由讯客互联创业栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“vue3背景虚化,文字高亮效果