前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Vue组件设计-文字悬停特效

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

作者头像
越陌度阡
发布2023-05-07 20:21:18
1.1K0
发布2023-05-07 20:21:18
举报

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

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

1. 组件设计实现

代码语言:javascript
复制
<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. 组件使用示例

代码语言:javascript
复制
<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>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-05-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 组件设计实现
  • 2. 组件使用示例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档