一个前端vue3文字hover效果

效果

组件代码

javascript 复制代码
<template>
  <span class="word-text" :style="[
    { transitionDuration: `${props.speed}ms` }
  ]">
    <slot></slot>
  </span>
</template>
  
<script setup>
const props = defineProps({
  // 动画速率 单位ms
  speed: {
    type: Number,
    default: 1000
  }
});
</script>
  
<style scoped>
.word-text {
  color: #ccc;
  background: linear-gradient(to right, #000, #000) no-repeat right bottom;
  background-size: 0% 2px;
  transition: background-size;
}
.word-text:hover {
  background-position-x: left;
  background-size: 100% 2px;
}
</style>

使用

javascript 复制代码
<template>
  <WordLine>你好我是文字啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊</WordLine>
</template>
  
<script setup>
import WordLine from "./WordLine.vue";
</script>
  
相关推荐
counterxing4 分钟前
vibe coding 之后,我更不想打字了
前端·agent·ai编程
copyer_xyf31 分钟前
Python 模块与包的导入导出
前端·后端·python
研☆香35 分钟前
es6新特性功能介绍(四)
前端·ecmascript·es6
微扬嘴角1 小时前
React篇1--JSX语法规则、组件、组件实例的3大特性
前端·react.js·前端框架
copyer_xyf1 小时前
Python venv 虚拟环境
前端·后端·python
无聊的老谢1 小时前
Vue 3 + TypeScript 构建大型电信运维平台的前端架构设计
前端·vue.js·typescript
xiaofeichaichai1 小时前
Map / Set / WeakMap / WeakSet
前端·javascript
李可以量化1 小时前
成交量的终极量化策略:价量共振指标完整实现(下篇)
前端·数据库·人工智能
copyer_xyf2 小时前
Python 如何同时做很多事:进程、线程、协程
前端·后端·python
gqk013 小时前
Delegate.Target/ Method
前端·ui·xhtml