鼠标hover及点击后动态显示相关元素样式

描述:

  1. 当鼠标hover或者点击时,当前元素显示被选中时样式
  2. 默认选中第一行
  3. 未选中的元素字体为黑色,且隐藏操作(编辑/删除)按钮
  4. 选中的元素字体为蓝色,显示操作按钮
  5. 选中的元素如果可以操作,则操作按钮展示蓝色/红色
  6. 选中的元素如果不可以操作,则操作按钮展示灰色

实现效果图:
在这里插入图片描述

<div class="container-left">

      <div :class="{ 'active': itemIndex == index, 'container-left-catelist': true }"
        v-for="(item, index) in cateData.cateList" :key="item.hrPerformanceGradeCategoryId"
        @click="getGradeList(index, item.hrPerformanceGradeCategoryId)" @mouseenter="enterCateItem($event, index)"
        @mouseleave="leaveCateItem($event, index)">
        <div class="container-left-catelist-item">{{ item.gradeCategoryName }}</div>
        
        <div
          :class="{ 'inactive': itemIndex != index, 'container-left-operatecate': true, 'cannot-operate': item.isUse == 1 }">
          <a-space>
            <span class="editCateBtn" @click="openOperateCateModal(operateType = 2, item)">编辑</span>
            <span class="delCateBtn" @click="delCate(item)">删除</span>
          </a-space>
        </div>
      </div>
      <a-button type="dashed" class="addCateBtn" @click="openOperateCateModal(operateType = 1, '')"> + 新增等级分类</a-button>
    </div>
const enterCateItem = (e: any, index: any) => {
  if (itemIndex.value == index) return
  e.currentTarget.classList.add('active')
}

const leaveCateItem = (e: any, index: any) => {
  if (itemIndex.value == index) return
  e.currentTarget.classList.remove('active')
}
.container-left-catelist {
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      padding: 0 1.25rem 0 1.25rem;
      margin-bottom: 1.5rem;
//hover时的样式
      &:hover {
        .container-left-operatecate {
          opacity: 1
        }
      }
       .active {
      .container-left-catelist-item {
        color: #6671FA;
        opacity: 1;

      }

      .editCateBtn {
        color: #6671FA;
        opacity: 1;

      }

      .delCateBtn {
        color: #F84726;
        opacity: 1;
      }
    }
    }

 // 分类item未选中的样式
  .inactive {
    opacity: 0;
  }

  // 分类item不能编辑时的样式
  .cannot-operate {
    span {
      color: #c6c6c6 !important;

    }
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值