css-mask遮罩的妙用

先看效果:

        遇到不规则div应该怎么画出来呢?css提供了两个样式可以实现,clip裁剪跟mask遮罩,clip有点麻烦就略过,直接说mask。
        mask类似background,遮罩可以理解成一块有洞的盖板,覆盖在最上一层,所以只能看到洞透过去的东西,一眼就会,直接上代码。

<template>
  <div class="mask-cpn">
    <div class="progress-wrap">
      <div class="progress-bar" ref="progressBarRef"></div>
      <div
        :style="{ paddingTop: `${progressBarHeight * ((100 - percent) / 100)}px` }"
        class="progress-bar progress-bar-active"
      ></div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},

  data() {
    return {
      percent: 20,
      progressBarHeight: 0
    }
  },
  mounted() {
    this.init()

    setInterval(() => {
      this.test()
    }, 300)
  },
  methods: {
    test() {
      this.percent = parseInt(Math.random() * 100)
    },
    init() {
      this.progressBarHeight = this.$refs.progressBarRef.offsetHeight
    }
  }
}
</script>

<style>
.mask-cpn {
  height: 212px;
  width: 165px;
  position: relative;
}
.progress-wrap {
  height: 100%;
  background: url(图片地址)
    28px 0px no-repeat;
}

.progress-bar {
  width: 165px;
  height: 204px;
  transition: all ease 0.2s;
  position: absolute;
  background-color: #244867;
  mask-image: url(//图片地址);
  mask-repeat: no-repeat;
  mask-position: center;
}
.progress-bar-active {
  z-index: 2;
  background: linear-gradient(to top, #41e0fe 40%, #9a8a82 60%, #ce5a3e 80%, #ff451b);
  background-clip: content-box;
}

</style>

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值