Vue 2.0组件设计-文字悬停特效

文章展示了如何使用Vue来创建一个具有动态悬停效果的文本组件。该组件在鼠标悬停时,通过CSS动画改变文字颜色和位置,常用于Logo或链接,增加页面交互性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

给大家分享一个基于Vue组件设计的文字悬停特效,实现的效果如下:

这种效果常见于一些Logo文字或是可点击的链接,使得页面看起来更加生动活跃。 

1. 组件设计实现

<template>
    <a :class="className" class="link-obj" href="#">
        {{ text }}
        <span :data-letters="text" />
        <span :data-letters="text" />
    </a>
</template>

<script>
export default {
    name:"TextHoverEffect",
    props: {
        className: {
            type: String,
            default: "",
        },
        text: {
            type: String,
            default: "后台管理系统",
        },
    },
};
</script>

<style>

.link-obj {
    font-weight: 800;
    color: #4dd9d5;
    font-family: "Dosis", sans-serif;
    -webkit-transition: color 0.5s 0.25s;
    transition: color 0.5s 0.25s;
    overflow: hidden;
    position: relative;
    display: inline-block;
    line-height: 1;
    outline: none;
    text-decoration: none;
}

.link-obj:hover {
    -webkit-transition: none;
    transition: none;
    color: transparent;
}

.link-obj::before {
    content: "";
    width: 100%;
    height: 6px;
    margin: -3px 0 0 0;
    background: #3888fa;
    position: absolute;
    left: 0;
    top: 50%;
    -webkit-transform: translate3d(-100%, 0, 0);
    transform: translate3d(-100%, 0, 0);
    -webkit-transition: -webkit-transform 0.4s;
    transition: transform 0.4s;
    -webkit-transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
    transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
}

.link-obj:hover::before {
    -webkit-transform: translate3d(100%, 0, 0);
    transform: translate3d(100%, 0, 0);
}

.link-obj span {
    position: absolute;
    height: 50%;
    width: 100%;
    left: 0;
    top: 0;
    overflow: hidden;
}

.link-obj span::before {
    content: attr(data-letters);
    color: red;
    position: absolute;
    left: 0;
    width: 100%;
    color: #3888fa;
    -webkit-transition: -webkit-transform 0.5s;
    transition: transform 0.5s;
}

.link-obj span:nth-child(2) {
    top: 50%;
}

.link-obj span:first-child::before {
    top: 0;
    -webkit-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
}

.link-obj span:nth-child(2)::before {
    bottom: 0;
    -webkit-transform: translate3d(0, -100%, 0);
    transform: translate3d(0, -100%, 0);
}

.link-obj:hover span::before {
    -webkit-transition-delay: 0.3s;
    transition-delay: 0.3s;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
    transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
</style>

2. 组件使用示例

<template>
    <div class="box">
        <TextHoverEffect :text="text"></TextHoverEffect>
    </div>
</template>

<script>

import TextHoverEffect from "@/components/TextHoverEffect";

export default {
    name:"index",
    components:{
        TextHoverEffect:TextHoverEffect
    },
    data() {
        return {
           text:"集团后台管理系统"
        };
    }
}
</script>


<style scoped>

.box{
    width:600px;
    margin:20px;
    padding:10px;
    background:#fff;
}

</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

艾光远

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值