CSS3動畫按鈕效果

admin發表於2018-07-04

本章節分享一段程式碼例項,它實現了簡單的動畫按鈕效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
.set {
  position: relative;
  font-weight: 400;
  text-align: center;
  width: 200px;
  line-height: 45px;
  overflow: hidden;
  position: relative;
  z-index: 0;
  color: #FFFFFF;
  background: #b9ccd2;
  cursor: pointer;
 }
 
.anim {
  transform: translateY(-50%) translateX(-50%);
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: -1;
}
.anim:before {
  position: relative;
  content: '';
  display: block;
  margin-top: 100%;
  background: #6CB1FF;
}
.anim:after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 50%;
}
.hoverable:hover > .anim:after {
  animation: anim-out-pseudo 0.75s;
}
.set:hover > .anim {
  animation: anim-out 0.75s;
}
@keyframes anim-out-pseudo {
  0% {
    background: rgba(0, 0, 0, 0.25);
  }
  100% {
    background: transparent;
  }
}
@keyframes anim-out {
  0% {
    width: 0%;
  }
  100% {
    width: 100%;
  }
}
</style>
</head>
<body>
<div class="set hoverable">
  <div class="anim"></div>
  <span>螞蟻部落</span>
</div>
</body>
</html>

相關文章