当前位置: 代码网 > it编程>编程语言>Javascript > vue项目实现背景颜色以及下划线从左到右渐变动画效果

vue项目实现背景颜色以及下划线从左到右渐变动画效果

2024年09月08日 Javascript 我要评论
vue项目:背景颜色、下划线从左到右渐变动画效果产品提了一个需求,让我写一个阿里云的切换动画效果。本来我很不情愿的,但是他说ui妹子下班请我吃饭,我就勉为其难的答应了。先来看看阿里云的效果鼠标放上去的

vue项目:背景颜色、下划线从左到右渐变动画效果

产品提了一个需求,让我写一个阿里云的切换动画效果。

本来我很不情愿的,但是他说ui妹子下班请我吃饭,我就勉为其难的答应了。

先来看看阿里云的效果

请添加图片描述

鼠标放上去的时候切换table,下面的线条有过渡效果。这个莎x产品还非说改成点击效果。ctm的。

再来看看我的demo效果

在这里插入图片描述

话不多说上代码

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
    #bottom {
        width: 63px;
        margin-top: 5px;
        margin-left: 17px;
        position: absolute;
        background: linear-gradient(to right, #f3edea, #f5b587, #ff6a00);
        padding-bottom: 3px;
        transform: scalex(0);
        transform-origin: left;
        transition: transform .15s ease-in-out;
    }

    .cnm {
        transform: scalex(1) !important;
    }

    .text {
        background-image: -webkit-linear-gradient(left, #f8e9de, #f5b587, #ff6a00);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        font-weight: 800;
    }



    /* ------------------以上为主要代码控制动画--------------------------- */


    p {
        margin: 0;
        padding: 0;
    }

    .box1 {
        width: 100px;
        margin: 20px 0;
        text-align: center;
    }

    section {
        width: 400px;
        display: flex;
        justify-content: center;
        border: 1px dashed #ff6a00;
    }

    .box2 {
        width: 95%;
        text-align: center;
        font-size: 30px;
        font-weight: 800;
        line-height: 266px;
    }
</style>

<body>

    <div id='app'>
        <section>
            <div>
                <div class="box1" v-for="(item,index) in list" :key="index" @click="handleclick(index)">
                    <p :class="{'text':actived==index}">{{item.name}}</p>
                    <div :class="{'cnm':actived==index}" id="bottom"></div>
                </div>
            </div>
            <div class="box2" v-show="actived==index?true:false" v-for="(item,index) in 6" :key="index">{{index+1}}
            </div>
        </section>
    </div>
    <script>
        var vm = new vue({
            el: '#app',
            data: {
                list: [
                    {
                        name: '移动云 >',
                        id: 0
                    },
                    {
                        name: '华为云 >',
                        id: 1
                    },
                    {
                        name: '阿里云 >',
                        id: 2
                    },
                    {
                        name: '腾讯云 >',
                        id: 3
                    },
                    {
                        name: '百度云 >',
                        id: 4
                    }, {
                        name: '京东云 >',
                        id: 5
                    }
                ],
                actived: 0
            },
            methods: {
                handleclick(index) {
                    this.actived = index
                }
            }
        })
    </script>
</body>

</html>

背景颜色自己改改样式吧!

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com