css3迴圈漸隱漸現效果程式碼例項

admin發表於2017-02-25

本章節分享一段程式碼例項,它利用css3實現了迴圈漸隱漸現效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
body {
  background-color: #efefef;
}
.main {
  width: 300px;
  height: 300px;
  border-radius: 10px;
  overflow: hidden;
}
.child {
  width: 100px;
  height: 100px;
  float: left;
  background-color: rgba(255,0,0,0.5);
  text-align: center;
  opacity: 0;
  line-height: 100px;
  animation-name: flash;
  animation-duration: 9s;
  animation-iteration-count: infinite;
}
.child:nth-child(1) {
  animation-delay: 0s;
}
.child:nth-child(2) {
  animation-delay: 0.5s;
}
.child:nth-child(3) {
  animation-delay: 1s;
}
.child:nth-child(4) {
  animation-delay: 3.5s;
}
.child:nth-child(5) {
  animation: none;
  background-color: #fff;
  opacity: 1;
}
.child:nth-child(6) {
  animation-delay: 1.5s;
}
.child:nth-child(7) {
  animation-delay: 3s;
}
.child:nth-child(8) {
  animation-delay: 2.5s;
}
.child:nth-child(9) {
  animation-delay: 2s;
}
@keyframes flash {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
</style>
</head>
<body>
  <div class="main">
    <div class="child child1">
      1
    </div>
    <div class="child child2">
      2
    </div>
    <div class="child child3">
      3
    </div>
    <div class="child child4">
      4
    </div>
    <div class="child child5">
      5
    </div>
    <div class="child child6">
      6
    </div>
    <div class="child child7">
      7
    </div>
    <div class="child child8">
      8
    </div>
    <div class="child child9">
      9
    </div>
  </div>
</body>
</html>

相關文章