首页前端开发HTMLhtml代码太阳系特效

html代码太阳系特效

时间2023-11-16 11:59:03发布访客分类HTML浏览993
导读:太阳系是我们所在的星系,由太阳和八大行星以及许多的卫星、矮行星、小行星、彗星、陨石和宇宙尘埃组成。为了呈现出太阳系的美丽和神秘感,我们可以使用html代码实现太阳系特效。<!DOCTYPE html><html>&l...

太阳系是我们所在的星系,由太阳和八大行星以及许多的卫星、矮行星、小行星、彗星、陨石和宇宙尘埃组成。为了呈现出太阳系的美丽和神秘感,我们可以使用html代码实现太阳系特效。

!DOCTYPE html>
    html>
    head>
      title>
    太阳系特效/title>
      style>
    body {
          background-color: black;
    }
    .sun {
          width: 200px;
          height: 200px;
          border-radius: 50%;
          background-color: yellow;
          position: absolute;
          top: 50%;
          left: 50%;
          margin-top: -100px;
          margin-left: -100px;
          animation: spin 10s infinite linear;
    }
    .planet {
          width: 50px;
          height: 50px;
          border-radius: 50%;
          background-color: #333;
          position: absolute;
          animation-name: orbit;
          animation-duration: x秒;
          animation-timing-function: linear;
          animation-delay: x秒;
          animation-iteration-count: infinite;
          transform-origin: center center;
          top: x%;
          left: x%;
    }
    @keyframes spin {
      0% {
            transform: rotate(0deg);
      }
      100% {
            transform: rotate(360deg);
      }
    }
    @keyframes orbit {
      0% {
            transform: rotate(0deg) translateX(x px) rotate(0deg);
      }
      100% {
            transform: rotate(360deg) translateX(x px) rotate(-360deg);
      }
    }
      /style>
    /head>
    body>
      div class="sun">
    /div>
      div class="planet" style="animation-duration: 6s;
    animation-delay: 2s;
    top: 25%;
    left: 30%;
    ">
    /div>
      div class="planet" style="animation-duration: 8s;
    animation-delay: 4s;
    top: 40%;
    left: 60%;
    ">
    /div>
      div class="planet" style="animation-duration: 10s;
    animation-delay: 6s;
    top: 60%;
    left: 20%;
    ">
    /div>
      div class="planet" style="animation-duration: 12s;
    animation-delay: 8s;
    top: 75%;
    left: 70%;
    ">
    /div>
    /body>
    /html>
    

在以上的代码中,我们定义了一个div样式为sun表示太阳,通过设置它的位置以及使用animation让它自转。同时定义多个div样式为planet表示各行星,通过设置它们的位置以及使用animation让它们绕太阳旋转,实现太阳系中行星的运动。这样通过html代码,我们就可以呈现出一个生动、美丽的太阳系特效。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: html代码太阳系特效
本文地址: https://pptw.com/jishu/541686.html
html代码太乱 html代码引入图片

游客 回复需填写必要信息