css3動態背景圖片程式碼例項

admin發表於2018-02-04
本章節分享一段程式碼例項,它實現了動態背景圖片效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
.pic {
  width: 1600px;
  height: 500px;
  overflow: hidden;
  position: relative;
}
.pic .img {
  background: url(demo/CSS/img/dongtai.jpg) no-repeat center center;
  height: 100%;
  animation: mymove 10s infinite;
  -webkit-animation: mymove 10s infinite;
}
@keyframes mymove {
  0% {
    background-position: center;
  }
  25% {
    background-position: top;
  }
  50% {
    background-position: center;
  }
  75% {
    background-position: bottom;
  }
  100% {
    background-position: center;
  }
}
.pic img {
  position: relative;
  animation: mymove2 10s infinite;
  -webkit-animation: mymove2 10s infinite;
}
@keyframes mymove2 {
  0% {
    top: -200px;
  }
  25% {
    top: 0;
  }
  50% {
    top: -200px;
  }
  75% {
    top: -400px;
  }
  100% {
    top: -200px;
  }
}
</style>
</head>
 
<body>
<div class="wrap">
  <div class="pic">
    <div class="img"></div>
  </div>
</div>
</body>
</html>

相關文章