CSS3星系运动效果代码实例

快乐打工仔 分类:实例代码

CSS3星系运动效果代码实例属于前端实例代码,有关更多实例代码大家可以查看

分享一段代码实例,它实现了简单的星系运动效果。

所谓的星系运动简单的说就是一群行星围绕一个恒星转动。

代码实例如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.pipipi.net/" />
<title>犀牛前端部落</title>
<style>
body {
margin: 0;
padding: 0;
background-image: url(bg.jpg);
}
ul {
width: 600px;
height: 600px;
margin: 40px auto;
position: relative;
list-style: none;
}
ul li {
border-radius: 50%;
position: absolute;
border: 2px solid #394057;
top: 50%;
left: 50%;
/*水平垂直居中*/
transform: translate(-50%, -50%);
/*2 把定义好的动画应用*/
animation-name: rotate;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
ul li span {
display: block;
position: absolute;
border-radius: 50%;
}
li:nth-child(1) {
width: 60px;
height: 60px;
border: none;
background-color: #c90;
box-shadow: 0 0 50px #c90;
animation-duration: 5s;
}
li:nth-child(2) {
width: 120px;
height: 120px;
animation-duration: 10s;
}
li:nth-child(2) span {
width: 12px;
height: 12px;
top: 25px;
background-color: yellow;
}
li:nth-child(3) {
width: 180px;
height: 180px;
animation-duration: 20s;
}
li:nth-child(3) span {
width: 12px;
height: 12px;
top: 48px;
background-color: blue;
}
li:nth-child(4) {
width: 240px;
height: 240px;
animation-duration: 30s;
}
li:nth-child(4) > span {
width: 12px;
height: 12px;
top: 72px;
background-color: green;
animation-name: rotate;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-duration: 1s;
}
li:nth-child(4) > span span {
width: 6px;
height: 6px;
position: absolute;
top: 16px;
background-color: yellow;
}
li:nth-child(5) {
width: 300px;
height: 300px;
animation-duration: 2s;
}
li:nth-child(5) span {
width: 16px;
height: 16px;
top: 90px;
background-color: red;
}
li:nth-child(6) {
width: 360px;
height: 360px;
}
li:nth-child(7) {
width: 420px;
height: 420px;
}
li:nth-child(8) {
width: 480px;
height: 480px;
}
li:nth-child(9) {
width: 540px;
height: 540px;
}
li:nth-child(10) {
width: 600px;
height: 600px;
}
/*定义动画*/
@keyframes rotate {
from {
transform: translate(-50%, -50%) rotate(0deg);
}
to {
transform: translate(-50%, -50%) rotate(360deg);
}
}
</style>
</head>
<body>
<ul>
<li></li>
<li><span></span></li>
<li><span></span></li>
<li>
<span><span></span></span>
</li>
<li><span></span></li>
<li><span></span></li>
<li>
<span><span></span></span>
</li>
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
</ul>
</body>
</html>

CSS3星系运动效果代码实例,这样的场景在实际项目中还是用的比较多的,关于CSS3星系运动效果代码实例就介绍到这了。

回复

我来回复
  • 暂无回复内容