css3 animation動畫程式碼例項

admin發表於2017-03-30

分享一段程式碼例項,它簡單演示了animation動畫效果。

實現了類似噴泉依次噴水的效果,程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
#water {
  width: 60px;
  height: 80px;
  background: #6389a8;
  z-index: -998;
  position: relative;
  transform: rotateZ(-45deg);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.15);
}
#water-drops div:nth-child(1) {
  position: absolute;
  background: #92b5d2;
  width: 10px;
  height: 0px;
  left: 15px;
  bottom: 570px;
  border-radius: 4px;
  z-index: 999;
  opacity: 0.4;
  animation: water-drops 2s ease infinite;
  animation-delay: .25s;
}
#water-drops div:nth-child(2) {
  position: absolute;
  background: #92b5d2;
  width: 10px;
  height: 0px;
  left: 25px;
  bottom: 560px;
  border-radius: 4px;
  z-index: 999;
  opacity: 0.4;
  animation: water-drops 2s ease infinite;
  animation-delay: .5s;
}
#water-drops div:nth-child(3) {
  position: absolute;
  background: #92b5d2;
  width: 10px;
  height: 0px;
  left: 35px;
  bottom: 550px;
  border-radius: 4px;
  z-index: 999;
  opacity: 0.4;
  animation: water-drops 2s ease infinite;
  animation-delay: .75s;
}
#water-drops div:nth-child(4) {
  position: absolute;
  background: #92b5d2;
  width: 10px;
  height: 0px;
  left: 45px;
  bottom: 540px;
  border-radius: 4px;
  z-index: 999;
  opacity: 0.4;
  animation: water-drops 2s ease infinite;
  animation-delay: 1s;
}
@keyframes water-drops {
  0% {
    height: 0;
    border-radius: 5px;
  }
  50% {
    height: 45px;
  }
  100% {
    height: 0;
  }
}
</style>
</head>
<body>
  <div id="water"></div>
  <div id="water-drops">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
</body>
</html>

相關文章