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>