产品提了一个需求,让我写一个阿里云的切换动画效果。
本来我很不情愿的,但是他说ui妹子下班请我吃饭,我就勉为其难的答应了。
鼠标放上去的时候切换table,下面的线条有过渡效果。这个莎x产品还非说改成点击效果。ctm的。
话不多说上代码
<!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>
背景颜色自己改改样式吧!
以上为个人经验,希望对您有所帮助。