0

0

html+ccs3太阳系行星运转动画_html/css_WEB-ITnose

php中文网

php中文网

发布时间:2016-06-24 11:16:08

|

1466人浏览过

|

来源于php中文网

原创

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

效果静态图:

 

动画中包括:太阳及各行星,运行轨道,行星公转动画。

立即学习前端免费学习笔记(深入)”;

先画好草图,设计好大小和位置,根据公转周期计算好动画执行的时间。

 

html的结构:

一个class为solarsys的div,作为太阳系容器元素,该div的position为relative。

行星轨道和行星都用div,position为absolute。

容器用relative和内部元素采用absolute的定位方式,比较简单的能实现效果,缺点就是大小是固定的。

    <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定位,页面内剧中对齐。

        .solarsys{            width: 800px;            height: 800px;;            position: relative;            margin: 0 auto;            background-color: #000000;            padding: 0;            transform: scale(1);        }

 

太阳div的css:

按照设计的大小和位置,设定宽高,left,top。

AI脑图
AI脑图

AI一键生成思维导图

下载

设定颜色。

通过把boder-radius生成50%,把一个正方形变成圆形。

通过box-shadow的4层颜色设置实现太阳光晕。

        .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。

        .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关键帧动画,线性永久执行,这里的执行时长是根据行星的公转周期计算出来。

        .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关键帧动画:

逆时针旋转。

        @keyframes rotate {            100% {                transform: rotate(-360deg);            }        }

 

基本结构完成。

仅在chrome中测试过。

 

全部代码:

<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'></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></body></html>

 

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法
pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法

本专题系统整理pixiv网页版官网入口及登录访问方式,涵盖官网登录页面直达路径、在线阅读入口及快速进入方法说明,帮助用户高效找到pixiv官方网站,实现便捷、安全的网页端浏览与账号登录体验。

616

2026.02.13

微博网页版主页入口与登录指南_官方网页端快速访问方法
微博网页版主页入口与登录指南_官方网页端快速访问方法

本专题系统整理微博网页版官方入口及网页端登录方式,涵盖首页直达地址、账号登录流程与常见访问问题说明,帮助用户快速找到微博官网主页,实现便捷、安全的网页端登录与内容浏览体验。

194

2026.02.13

Flutter跨平台开发与状态管理实战
Flutter跨平台开发与状态管理实战

本专题围绕Flutter框架展开,系统讲解跨平台UI构建原理与状态管理方案。内容涵盖Widget生命周期、路由管理、Provider与Bloc状态管理模式、网络请求封装及性能优化技巧。通过实战项目演示,帮助开发者构建流畅、可维护的跨平台移动应用。

91

2026.02.13

TypeScript工程化开发与Vite构建优化实践
TypeScript工程化开发与Vite构建优化实践

本专题面向前端开发者,深入讲解 TypeScript 类型系统与大型项目结构设计方法,并结合 Vite 构建工具优化前端工程化流程。内容包括模块化设计、类型声明管理、代码分割、热更新原理以及构建性能调优。通过完整项目示例,帮助开发者提升代码可维护性与开发效率。

20

2026.02.13

Redis高可用架构与分布式缓存实战
Redis高可用架构与分布式缓存实战

本专题围绕 Redis 在高并发系统中的应用展开,系统讲解主从复制、哨兵机制、Cluster 集群模式及数据分片原理。内容涵盖缓存穿透与雪崩解决方案、分布式锁实现、热点数据优化及持久化策略。通过真实业务场景演示,帮助开发者构建高可用、可扩展的分布式缓存系统。

54

2026.02.13

c语言 数据类型
c语言 数据类型

本专题整合了c语言数据类型相关内容,阅读专题下面的文章了解更多详细内容。

29

2026.02.12

雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法
雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法

本专题系统整理雨课堂网页版官方入口及在线登录方式,涵盖账号登录流程、官方直连入口及平台访问方法说明,帮助师生用户快速进入雨课堂在线教学平台,实现便捷、高效的课程学习与教学管理体验。

15

2026.02.12

豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法
豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法

本专题汇总豆包AI官方网页版入口及在线使用方式,涵盖智能写作工具、图片生成体验入口和官网登录方法,帮助用户快速直达豆包AI平台,高效完成文本创作与AI生图任务,实现便捷智能创作体验。

598

2026.02.12

PostgreSQL性能优化与索引调优实战
PostgreSQL性能优化与索引调优实战

本专题面向后端开发与数据库工程师,深入讲解 PostgreSQL 查询优化原理与索引机制。内容包括执行计划分析、常见索引类型对比、慢查询优化策略、事务隔离级别以及高并发场景下的性能调优技巧。通过实战案例解析,帮助开发者提升数据库响应速度与系统稳定性。

56

2026.02.12

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号