天天看點

vue寫導航欄高亮顯示的過渡動畫效果

vue寫導航欄高亮顯示的過渡動畫效果

類似下面這種樣式

vue寫導航欄高亮顯示的過渡動畫效果

直接上代碼

<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: 100px;
        position: absolute;
        border-bottom: 2px solid #ff6a00;
        padding-bottom: 6px;
        transform: scaleX(0);
        transform-origin: left;
        transition: transform .15s ease-in-out;
    }
    .nav-bottom{
        transform: scaleX(1) !important;
    }
    .nav-text{
        color: #ff6a00;
    }
    p{
        margin: 0;
        padding: 0;
    }
    .nav-change{
        width: 100px;
        margin:50px auto;
        text-align: center;
    }
</style>

<body>

    <div id='app'>
        <div class="nav-change" v-for="(item,index) in list" :key="index" @mouseenter="handleClick(index)">
            <p :class="{'nav-text':actived==index}">{{item.name}}</p>
            <div :class="{'nav-bottom':actived==index}" id="bottom"></div>
        </div>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                list:[
                    {
                        name:'娛樂',
                        id:0
                    },
                    {
                        name:'科技',
                        id:1
                    },
                    {
                        name:'新聞',
                        id:2
                    }
                ],
                actived:0
            },
            methods: {
                handleClick(index){
                    this.actived=index
                }
            }
        })
    </script>
</body>

</html>