zoukankan      html  css  js  c++  java
  • vue中切换标签的选中效果添加平移效果

    点击后不是直接改变选中的样式,而是移动效果:

     实现的代码:

     <template>
    <div class="StepCell"> <a class="move" ref="move" :style="moveStyle"></a> <div class="d-f-a h-100p"> <a class="step-item" :class="{'active':stepVal==item.num}" :ref="'item'+index" v-for="item,index in stepList" :key="index" @click="stepFun(item,index)"> <span class="name">{{item.name}}</span> </a> </div> </div> </template> <script> export default { components: { }, data() { return { stepList: [ { name: "1", num: 6 }, { name: "2", num: 8 }, { name: "3", num: 12 }, { name: "4", num: 20 }, { name: "5", num: 10 }, ], stepVal: "", stepIndex: 0, moveStyle: {} } }, mounted() { this.stepFun(this.stepList[0],0); // 默认选中第一个 window.onresize = ()=> { this.stepFun(this.stepList[ this.stepIndex ],this.stepIndex); } }, methods: { /** * 步骤点击选中事件 */ stepFun(item,index) { this.stepIndex = index; let moveStyle = this.$refs.move.getBoundingClientRect(); let itemStyle = this.$refs["item"+index][0].getBoundingClientRect(); let itemWidth = itemStyle.width; this.moveStyle = { left: itemStyle.left + "px", } this.stepVal = item.num; this.$emit('getStepActive',item.num); } } }; </script> <style lang="stylus" scoped> .StepCell { position relative; height: 278px; .step-item { position relative; display: inline-block; 138px; height: 138px; line-height: 138px; margin-top: 76px; color: $mainColor; text-align: center; border: solid 1px $mainColor; border-radius: 50%; &.step-item { background-size: 50px; } .name { position: absolute; top: -90px; SetCenterX(); font-size: 20px; white-space: nowrap; } &.active { color: $mainColor1; border: none; &:before { background: none; } &.step-item { background-size: 50px; } .name { top: -100px; font-size: 28px; font-weight: bold; } } } .move{ 138px; height: 138px; position: absolute; top: 76px; transition: left .2s ease-in-out 0s; // 透明圈 &:before { content: ""; position: absolute; top: -((194 - 138)/2 + 40)px; left: -((194 - 138)/2 + 40)px; 194px; height: 194px; background-color: rgba(255, 228, 0, 0.2); background-clip: padding-box; border: solid 40px rgba(255, 228, 0, 0.1); border-radius: 50%; } } } </style>>

    里面用到了stylus变量和函数

    $mainColor = #00ebff; 
    $mainColor1 = #ffe400;
    SetCenterX() {
        position: absolute;
        left: 50%;
        transform: translate(-50%);
    }
    公共的类名
    .d-f-a {
        display: flex;
        justify-content: space-around;
    }
    .h-100p {
        height: 100%;
    }
     
     
  • 相关阅读:
    动手做第一个Chrome插件
    Discuz NT 架构剖析之Config机制
    用游标实现查询当前服务器所有数据库所有表的SQL
    Discuz X3.2 网站快照被劫持的解决方法
    centos下MYSQL 没有ROOT用户的解决方法。
    redis命令1
    在当今快节奏的软件更迭当中,我们是否还需要进行系统的学习?
    StructureMap 代码分析之Widget 之Registry 分析 (1)
    C#面试题汇总(未完成)
    C#:解决WCF中服务引用 自动生成代码不全的问题。
  • 原文地址:https://www.cnblogs.com/stella1024/p/13094678.html
Copyright © 2011-2022 走看看