LY Front-end Dev Engineer

css实现ripple点击效果

2016-01-18
LY

利用transition、before、after实现ripple的效果

原理

.demo-btn {
  position: relative;
  width: 200px;
  height: 40px;
  margin: 15px auto;
  color: #fff;
  font-size: 20px;
  line-height: 40px;
  background-color: #000;
  cursor: pointer;
  text-align: center;
}
.demo-btn::before,
.demo-btn::after {
  display: block;
  content: '';
  position: absolute;
}
.demo-btn,
.demo-btn::before,
.demo-btn::after {
  -webkit-transition: all .3s;
  transition: all .3s;
}
.demo-btn::before,
.demo-btn::after {
  top: 0;
  width: 50%;
  height: 100%;
}
.demo-btn::before {
  right: 0;
}
.demo-btn::after {
  left: 0;
}
.demo-btn:hover::before,
.demo-btn:hover::after{
  width: 0;
  background-color: #59b1eb;
}
.demo-btn:hover{
  border-color: #3DC4D8;
  color: #FFF;
  background-color: #3DC4D8;
} 

Comments

Content