纯css实现涟漪效果

<template>
  <div id="app">
    <el-button type="primary" class="primary"
      >按钮一 <span class="mask mask-1"></span
    ></el-button>
    <el-button type="success" class="success"
      >按钮二<span class="mask mask-2"></span
    ></el-button>
    <el-button type="info" class="info"
      >按钮三<span class="mask mask-3"></span
    ></el-button>
    <el-button type="warning" class="warning"
      >按钮四<span class="mask mask-4"></span
    ></el-button>
  </div>
</template>

<script>
export default {
  name: "app",
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.el-button {
  position: relative;
}
/*定义一个遮罩层,这是实现的核心 */
.mask {
  position: absolute;
  display: block;
  /*在这里宽高的初始值没必要设置 */
  height: 100%;
  background-color: #fff;
  opacity: 1;
}
/*每个按钮不同的遮罩效果 */
.mask-1 {
  top: 0;
  right: 0;
}
.mask-2 {
  top: 0;
  left: 0;
  border-top-right-radius: 40px;
}
.mask-3 {
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
}
.mask-4 {
  left: 0;
  bottom: 0;
  height: 0;
  width: 100%;
  opacity: 1;
  border-radius: 4px;
}
/**鼠标悬停按钮时触发动画 */
.primary:hover .mask {
  /* 动画名称 */
  animation-name: btn-animation-one;
  animation-duration: 1s;
}
.success:hover .mask {
  /* 动画名称 */
  animation-name: btn-animation-one;
  animation-duration: 1s;
}
.info:hover .mask {
  /* 动画名称 */
  animation-name: btn-animation-three;
  animation-duration: 1s;
}
.warning:hover .mask {
  /* 动画名称 */
  animation-name: btn-animation-four;
  animation-duration: 1s;
}

/* 定义动画 */
@keyframes btn-animation-one {
  from {/*开始状态 */
    width: 0;
    opacity: 1;
  }
  to {/*结束状态 */
    width: 100%;
    opacity: 0;
  }
}
/* 该动画效果失败 */
@keyframes btn-animation-three {
  from { 
    width: 1px;
    height: 1px;
    transform: scale(0);
    opacity: 1;

  }
  to { 
    width: 1px;
    height: 1px;
    transform: scale(100);
    opacity: 0;
  }
}
@keyframes btn-animation-four {
  from {
    width: 100%;
    height: 0;
    opacity: 1;
  }
  to {
    height: 100%;
    width: 100%;
    opacity: 0;
  }
}
</style>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值