做一个太阳系八大行星的运转动画,不包括行星的卫星,所有行星围绕太阳公转,行星采用纯色,暂时没有自转。
效果静态图:

动画中包括:太阳及各行星,运行轨道,行星公转动画。
先画好草图,设计好大小和位置,根据公转周期计算好动画执行的时间。
html的结构:
一个class为solarsys的div,作为太阳系容器元素,该div的position为relative。
行星轨道和行星都用div,position为absolute。
容器用relative和内部元素采用absolute的定位方式,比较简单的能实现效果,缺点就是大小是固定的。
XML/HTML Code复制内容到剪贴板
- <div class="solarsys">
-
- <div class='sun'></div>
-
-
- <div class='mercuryOrbit'></div>
-
-
- <div class='mercury'></div>
-
-
- <div class='venusOrbit'></div>
-
-
- <div class='venus'></div>
-
-
- <div class='earthOrbit'></div>
-
-
- <div class='earth'></div>
-
-
- <div class='marsOrbit'></div>
-
-
- <div class='mars'></div>
-
-
- <div class='jupiterOrbit'></div>
-
-
- <div class='jupiter'></div>
-
-
- <div class='saturnOrbit'></div>
-
-
- <div class='saturn'></div>
-
-
- <div class='uranusOrbit'></div>
-
-
- <div class='uranus'></div>
-
-
- <div class='neptuneOrbit'></div>
-
-
- <div class='neptune'></div>
- </div>
太阳系容器div的css:
定宽,定高,relative定位,页面内剧中对齐。
CSS Code复制内容到剪贴板
- .solarsys{
- width: 800px;
- height: 800px;;
- position: relative;
- margin: 0 auto;
- background-color: #000000;
- padding: 0;
- transform: scale(1);
- }
太阳div的css:
按照设计的大小和位置,设定宽高,left,top。
设定颜色。
通过把boder-radius生成50%,把一个正方形变成圆形。
通过box-shadow的4层颜色设置实现太阳光晕。
CSS Code复制内容到剪贴板
- .sun {
- left:357px;
- top:357px;
- height: 90px;
- width: 90px;
- background-color: rgb(248,107,35);
- border-radius: 50%;
- box-shadow: 5px 5px 10px rgb(248,107,35), -5px -5px 10px rgb(248,107,35), 5px -5px 10px rgb(248,107,35), -5px 5px 10px rgb(248,107,35);
- position: absolute;
- margin: 0;
- }
行星轨道div的css:
假设是水星轨道。
按照设计的大小和位置,设定宽高,left,top。
背景色透明。
通过把boder-radius生成50%,把一个正方形变成圆形。
boder的类型设成虚线。
boder的颜色设成灰色。
宽度设1。
CSS Code复制内容到剪贴板
- .mercuryOrbit {
- left:342.5px;
- top:342.5px;
- height: 115px;
- width: 115px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- margin: 0px;
- padding: 0px;
- }
行星div的css:
假设是水星。
按照设计的大小和位置,设定宽高,left,top。
设置颜色。
通过把boder-radius生成50%,把一个正方形变成圆形。
将transfrom-origin设定成当前div的左上角相对于整个太阳系容器的中心点的横向和纵向的偏移量。加上旋转动画后就是围绕着中心点旋转效果。
做一个animation,引用rotate关键帧动画,线性永久执行,这里的执行时长是根据行星的公转周期计算出来。
CSS Code复制内容到剪贴板
- .mercury {
- left:337.5px;
- top:395px;
- height: 10px;
- width: 10px;
- background-color: rgb(166,138,56);
- border-radius: 50%;
- position: absolute;
- transform-origin: 62.5px 5px;
- animation: rotate 1.5s infinite linear;
- }
rotate关键帧动画:
逆时针旋转。
CSS Code复制内容到剪贴板
- @keyframes rotate {
- 100% {
- transform: rotate(-360deg);
- }
- }
基本结构完成。
仅在chrome中测试过。
全部代码:
XML/HTML Code复制内容到剪贴板
- <html>
- <head>
- <style>
- .solarsys{
- width: 800px;
- height: 800px;;
- position: relative;
- margin: 0 auto;
- background-color: #000000;
- padding: 0;
- transform: scale(1);
- }
-
- /*太阳*/
- .sun {
- left:357px;
- top:357px;
- height: 90px;
- width: 90px;
- background-color: rgb(248,107,35);
- border-radius: 50%;
- box-shadow: 5px 5px 10px rgb(248,107,35), -5px -5px 10px rgb(248,107,35), 5px -5px 10px rgb(248,107,35), -5px 5px 10px rgb(248,107,35);
- position: absolute;
- margin: 0;
- }
-
- /*水星*/
- .mercury {
- left:337.5px;
- top:395px;
- height: 10px;
- width: 10px;
- background-color: rgb(166,138,56);
- border-radius: 50%;
- position: absolute;
- transform-origin: 62.5px 5px;
- animation: rotate 1.5s infinite linear;
- }
-
- /*水星轨道*/
- .mercuryOrbit {
- left:342.5px;
- top:342.5px;
- height: 115px;
- width: 115px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- margin: 0px;
- padding: 0px;
- }
-
- /*金星*/
- .venus {
- left:309px;
- top:389px;
- height: 22px;
- width: 22px;
- background-color: rgb(246,157,97);
- border-radius: 50%;
- position: absolute;
- transform-origin: 91px 11px;
- animation: rotate 3.84s infinite linear;
- }
-
- /*金星轨道*/
- .venusOrbit {
- left:320px;
- top:320px;
- height: 160px;
- width: 160px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- /*margin: 100px;*/
- /*transform-origin: -75px -75px;*/
- /*animation: rotate 4s infinite linear;*/
- margin: 0px;
- padding: 0px;
- }
-
- /*地球*/
- .earth {
- left:266.5px;
- top:391px;
- height: 18px;
- width: 18px;
- background-color: rgb(115,114,174);
- border-radius: 50%;
- position: absolute;
- transform-origin: 134px 9px;
- animation: rotate 6.25s infinite linear;
- }
-
- /*地球轨道*/
- .earthOrbit {
- left:275px;
- top:275px;
- height: 250px;
- width: 250px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- /*margin: 100px;*/
- /*transform-origin: -75px -75px;*/
- /*animation: rotate 4s infinite linear;*/
- margin: 0px;
- padding: 0px;
- }
-
- /*火星*/
- .mars {
- left:222.5px;
- top:392.5px;
- height: 15px;
- width: 15px;
- background-color: rgb(140,119,63);
- border-radius: 50%;
- position: absolute;
- transform-origin: 177.5px 7.5px;
- animation: rotate 11.75s infinite linear;
- }
-
- /*火星轨道*/
- .marsOrbit {
- left:230px;
- top:230px;
- height: 340px;
- width: 340px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- /*margin: 100px;*/
- /*transform-origin: -75px -75px;*/
- /*animation: rotate 4s infinite linear;*/
- margin: 0px;
- padding: 0px;
- }
-
- /*木星*/
- .jupiter {
- left:134px;
- top:379px;
- height: 42px;
- width: 42px;
- background-color: rgb(156,164,143);
- border-radius: 50%;
- position: absolute;
- transform-origin: 266px 21px;
- animation: rotate 74.04s infinite linear;
- }
-
- /*木星轨道*/
- .jupiterOrbit {
- left:155px;
- top:155px;
- height: 490px;
- width: 490px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- /*margin: 100px;*/
- /*transform-origin: -75px -75px;*/
- /*animation: rotate 4s infinite linear;*/
- margin: 0px;
- padding: 0px;
- }
-
- /*土星*/
- .saturn {
- left:92px;
- top:387px;
- height: 26px;
- width: 26px;
- background-color: rgb(215,171,68);
- border-radius: 50%;
- position: absolute;
- transform-origin: 308px 13px;
- animation: rotate 183.92s infinite linear;
- }
-
- /*土星轨道*/
- .saturnOrbit {
- left:105px;
- top:105px;
- height: 590px;
- width: 590px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- /*margin: 100px;*/
- /*transform-origin: -75px -75px;*/
- /*animation: rotate 4s infinite linear;*/
- margin: 0px;
- padding: 0px;
- }
-
- /*天王星*/
- .uranus {
- left:41.5px;
- top:386.5px;
- height: 27px;
- width: 27px;
- background-color: rgb(164,192,206);
- border-radius: 50%;
- position: absolute;
- transform-origin: 358.5px 13.5px;
- animation: rotate 524.46s infinite linear;
- }
-
- /*天王星轨道*/
- .uranusOrbit {
- left:55px;
- top:55px;
- height: 690px;
- width: 690px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- /*margin: 100px;*/
- /*transform-origin: -75px -75px;*/
- /*animation: rotate 4s infinite linear;*/
- margin: 0px;
- padding: 0px;
- }
-
- /*海王星*/
- .neptune {
- left:10px;
- top:390px;
- height: 20px;
- width: 20px;
- background-color: rgb(133,136,180);
- border-radius: 50%;
- position: absolute;
- transform-origin: 390px 10px;
- animation: rotate 1028.76s infinite linear;
- }
-
- /*海王星轨道*/
- .neptuneOrbit {
- left:20px;
- top:20px;
- height: 760px;
- width: 760px;
- background-color: transparent;
- border-radius: 50%;
- border-style: dashed;
- border-color: gray;
- position: absolute;
- border-width: 1px;
- /*margin: 100px;*/
- /*transform-origin: -75px -75px;*/
- /*animation: rotate 4s infinite linear;*/
- margin: 0px;
- padding: 0px;
- }
-
- @keyframes rotate {
- 100% {
- transform: rotate(-360deg);
- }
- }
-
- </style>
-
- </head>
- <body>
- <div class="solarsys">
-
- <div class='sun'></div>
-
-
- <div class='mercuryOrbit'></div>
-
-
- <div class='mercury'></div>
-
-
- <div class='venusOrbit'><
网页注释在IE中产生文字溢出
实验代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transiti
收藏 0赞 0分享
HTML教程:定义列表
原文:http://andymao.com/andy/post/104.html
上一节:有序列表
写完“无序列表”和“有序列表”之后已经有人和我说这两篇看得没什么意思。这两篇文章如果只以单向读取的形式阅读那么的确是没什
收藏 0赞 0分享
HTML教程:有序列表
原文:http://andymao.com/andy/post/103.html
上一节:无序列表
信息有时候是无序归纳的,有的却有着明确的顺序,在上一篇也提到了。那么简单的来想一下身边有哪些事物是有先后顺序的:操作步骤、排行榜、书目录……
收藏 0赞 0分享
HTML教程:无序列表
原文:http://andymao.com/andy/post/102.html
段落已经讲完了,那么一些基本的应用方式也讲了一些,那么是否已经应用了呢?当然应用可以更为丰富,那么这些就需要自己在实际工作中不断的摸索与思考,然后创新并总结得出新的应用形式。当然了段落不能当作
收藏 0赞 0分享
HTML网页制作的强大8条技巧
虽然现在有许多网页制作工具能让您轻松地完成工作,但如果使用HTML则可以得到更大控制权,下面介绍几个小技巧。
1。使用<tt>,<i>,<br>语句来控制文字排版比用<pre>好得多。 如: <tt>实用
收藏 0赞 0分享
网页表格分割线去除方法
网页表格分割线去除方法。
其实上面的三个表格都有三行三列,隐藏分隔线的诀窍在于rules,察看这三个表格的源代码,我们可以看到<TABLE>标签中都有rules。它有三个参数(cols,rows,none),当rules=cols时,表格会隐藏纵向的分隔线,这
收藏 0赞 0分享
blockquote标记应用注意
关于语义化,不是一句两句就能说明白的,而且现在也没有一个官方的很严格的定义。关于<blockquote>没有争议的是:
1.引用一段较长的文字
2.可以使用cite标签或者属性
问题是<blockquote>引用的文字必须使用块级元素将他
收藏 0赞 0分享
网页表格表框制作技巧
网页表格表框制作技巧。
--------------------------------------------------------------------------------
表格边框的显示与隐藏,是可以用frame参数来控制的。请注意它只控制表格的边框图,而不
收藏 0赞 0分享
HTML其实就是学习几个重要标记的应用
《这将是一场革命》一文出来以后。得到业界大伙的认同,当然与此同时也得到部分来自内部与外部的挑衅,不过的更加多的是更多人来寻问每一个点的细节。今晚回家很早就睡了,半夜在一个梦中醒来,梦里正在和小学的同学玩一个游戏——“The Next&rdquo
收藏 0赞 0分享
移动端专用的meta标签设置大全
不知道有没有人觉得,html的meta标签描述的头部信息特别多,下面这篇文章主要给大家分享介绍了关于移动端专用的meta设置的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧
收藏 0赞 0分享
查看更多