vue通过css实现页面的挖空效果(某一块高亮)

如图
案例图


方法一:使用box-shadow

  • 创建节点
 <div ref='li_2'>

  • 然后获取节点信息
 mounted() {
    const Dom = this.$refs.li_2[0]
    this.BoundingClientRect = Dom.getBoundingClientRect()
  },
  • 页面添加蒙层
 <div class="mask" :style="{top:BoundingClientRect.y+'px',left:BoundingClientRect.x+'px',width:BoundingClientRect.width+'px',height:BoundingClientRect.height+'px'}"></div>
  • 最后写css
.mask{
    position: fixed;
    box-shadow: 0 0 0px 100vh  rgba(0,0,0,0.5);
    z-index: 99999;
    &::before{
      content: ' ';
      display: block;
      width: 100vw;
      height: 100vh;
      position: fixed;
      top: 0;
      left: 0;
    }
  }

方法二:使用border

  • 创建节点
 <div ref='li_2'>

  • 然后获取节点信息
 mounted() {
    const Dom = this.$refs.li_2[0]
    this.BoundingClientRect = Dom.getBoundingClientRect()
  },
  • 页面添加蒙层
 <div class="mask" :style="{top:BoundingClientRect.y+'px',left:BoundingClientRect.x+'px',width:BoundingClientRect.width+'px',height:BoundingClientRect.height+'px'}"></div>
  • 最后写css
.mask{
    position: fixed;
    border: 100vh solid rgba(0,0,0,0.5);
    box-sizing: content-box;
    z-index: 99999;
    margin-left: -100vh;
    margin-top: -100vh;
  }

方法三:使用clip-path

  • 创建节点
 <div ref='li_2'>

  • 然后获取节点信息
 mounted() {
    const Dom = this.$refs.li_2[0]
    this.BoundingClientRect = Dom.getBoundingClientRect()
  },
  • 页面添加蒙层
 <div class="mask" :style="{'--top':BoundingClientRect.y+'px','--left':BoundingClientRect.x+'px','--right':(BoundingClientRect.x+BoundingClientRect.width)+'px','--bottom':(BoundingClientRect.y+BoundingClientRect.height)+'px'}"></div>
  • 最后写css
.mask{
    position: fixed;
    width: 100vw;
    height: 100vh;
    top: 0;
    left: 0;
    z-index: 99999;
    &::before{
      content: ' ';
      display: block;
      width: 100vw;
      height: 100vh;
      background-color: rgba(0,0,0,0.5);
      top: 0;
      left: 0;
      //从0 0 出发,画一圈矩形后,回到0 0,然后再到页面的四个角,就可以将页面挖出来了(So:这个方法可以挖不规则的图像)
      clip-path: polygon(0 0,var(--left) var(--top),var(--right) var(--top),var(--right) var(--bottom),var(--left) var(--bottom),var(--left) var(--top),0 0,0 100%,100% 100%, 100% 0,0 0);
    }
  }
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值