css+js 实现卡片悬停放大动画,其他元素缩小模糊效果

效果图如下:

在这里插入图片描述
在这里插入图片描述
之前看有人通过 纯css 实现,通过 父元素 框选 子元素实现,会有一个问题,当我鼠标在 白色空白区域,也会触发 模糊效果。
我想实现的效果是,只有在 灰色区域才触发效果。

    <div class="container">
      <div
        v-for="(item, index) in cardList"
        :key="item.id"
        class="card"
        :class="`${item.isSelect === 'select' ? 'select-card' : item.isSelect === 'not-select' ? 'not-select' : ''} `"
        @mouseleave="mouseLeaveOne(item.id)"
        @mouseenter="mouseOverOne(item.id)"
      >
        <div class="name">{{ item.name }}</div>
      </div>
    </div>
cardList: [
        { id: 1, name: "lllsj1" },
        { id: 2, name: "lllsj2" },
        { id: 3, name: "lllsj13" },
        { id: 4, name: "lllsj14" },
        { id: 5, name: "lllsj15" },
        { id: 6, name: "lllsj6" },
        { id: 7, name: "lllsj17" },
        { id: 8, name: "lllsj17" },
        { id: 9, name: "lllsj17" },
        { id: 10, name: "lllsj17" },
      ],
  mounted() {
    this.cardList.forEach(item => {
      this.$set(item, "isSelect", "normal");
    });
  },
   mouseLeaveOne(id) {
      this.cardList.forEach(item => {
        this.$set(item, "isSelect", "normal");
      });
    },
    mouseOverOne(id) {
      this.cardList.forEach(item => {
        this.$set(item, "isSelect", "not-select");
        if (item.id === id) {
          this.$set(item, "isSelect", "select");
        }
      });
    },
.container {
  // height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-wrap: wrap;

  .card {
    width: 200px;
    height: 200px;
    background: #ccc;
    border: 1px solid #ccc;
    transition: 0.5s ease;
    margin: 10px;
  }
  .not-select {
    filter: blur(10px);
    transform: scale(0.9);
    opacity: 0.8;
    background: green;
  }
  .select-card {
    background: yellow;
    filter: blur(0);
    transform: scale(1.1);
    opacity: 1;
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值