CSS3日食效果程式碼

螞蟻小編發表於2018-07-02
分享一段程式碼例項,它利用css3實現了日食效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
* {
  margin: 0;
  padding: 0;
}
body {
  background: #222;
}
.sky {
  position: relative;
  padding-top: 15px;
  width: 800px;
  height: 600px;
  margin: 150px auto;
}
.moon {
  margin: 0 auto;
  width: 200px;
  height: 200px;
  background-color: #f3f3f3;
  border-radius: 50%;
  box-shadow:6px 6px 10px #666, 6px -6px 10px #666, -6px 6px 10px #666, -6px -6px 10px #666;
}
.dog {
  position: absolute;
  top: 15px;
  left: 90px;
  width: 200px;
  height: 200px;
  background-color: #222;
  border-radius: 50%;
  animation: dogEatMoon 8s ease-out infinite;
}
@keyframes dogEatMoon {
  0% {
    left: 90px;
  }
  35% {
    left: 300px;
  }
  55% {
    left: 300px;
  }
  100% {
    left: 520px;
  }
}
</style>
</head>
<body>
  <div class="sky">
    <div class="moon"></div>
    <div class="dog"></div>
  </div>
</body>
</html>

相關文章