svg+css实现飞船跟随鼠标移动宇宙飞行动画效果代码

代码语言:html

所属分类:动画

代码描述:svg+css实现飞船跟随鼠标移动宇宙飞行动画效果代码

代码标签: svg css 飞船 跟随 鼠标 移动 宇宙 飞行 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  
  
  
<style>
@import url("https://fonts.googleapis.com/css?family=Roboto+Condensed");
html {
  cursor: url("//repo.bfw.wiki/bfwrepo/images/space/cybernoid_ship.png"), auto;
}

body {
  background: black;
  overflow: hidden;
}

.otherstuff {
  position: absolute;
  bottom: -2px;
  left: 10px;
  width: 180px;
  line-height: 50%;
  height: 30px;
  color: #444;
  font-size: 20px;
  text-decoration: none;
  font-family: "Roboto Condensed";
  opacity: 0.25;
}

span {
  position: relative;
  top: -3px;
  left: 5px;
  color: #fff;
}

.otherstuff:hover {
  color: #fff;
  opacity: 1;
  transition: color 0.2s linear, opacity 0.2s linear;
}

svg.star, svg.star1, svg.star2, svg.star3, svg.star4, svg.star5, svg.star6, svg.star7 {
  position: absolute;
  left: -110px;
  top: -110px;
}

svg.star1 {
  left: 160px;
  top: 80px;
}

svg.star2 {
  left: 30px;
  top: 140px;
}

svg.star3 {
  left: 70px;
  top: 40px;
}

svg.star4, svg.star41, svg.star42, svg.star43, svg.star44, svg.star45, svg.star46 {
  position: absolute;
  left: 220px;
  top: 180px;
  width: 20px;
  height: 20px;
  opacity: 0.4;
}

svg.star41 {
  left: 80%;
  top: 25%;
}

svg.star42 {
  left: 95%;
  top: 75%;
}

svg.star43 {
  left: 40%;
  top: 65%;
}

svg.star44 {
  left: 50%;
  top: 5%;
}

svg.star45 {
  left: 35%;
  top: 15%;
}

svg.star46 {
  left: 6%;
  top: 14%;
}

svg.star5 {
  left: 16.67%;
  top: 4%;
  width: 20px;
  height: 20px;
  transform-origin: center;
}

svg.star5 {
  z-index: 1;
  overflow: hidden;
  left: 2000px;
  width: 20px;
  height: 20px;
}
svg.star5:nth-child(1) {
  top: 77%;
  animation: s1 8s linear infinite;
  animation-delay: -1400ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s1 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(532deg);
  }
}
svg.star5:nth-child(2) {
  top: 41%;
  animation: s2 8s linear infinite;
  animation-delay: -2800ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s2 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(140deg);
  }
}
svg.star5:nth-child(3) {
  top: 94%;
  animation: s3 8s linear infinite;
  animation-delay: -4200ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s3 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(449deg);
  }
}
svg.star5:nth-child(4) {
  top: 59%;
  animation: s4 8s linear infinite;
  animation-delay: -5600ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s4 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(735deg);
  }
}
svg.star5:nth-child(5) {
  top: 20%;
  animation: s5 8s linear infinite;
  animation-delay: -7000ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s5 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(183deg);
  }
}
svg.star5:nth-child(6) {
  top: 39%;
  animation: s6 8s linear infinite;
  animation-delay: -8400ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s6 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(114deg);
  }
}
svg.star5:nth-child(7) {
  top: 85%;
  animation: s7 8s linear infinite;
  animation-delay: -9800ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s7 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(444deg);
  }
}
svg.star5:nth-child(8) {
  top: 13%;
  animation: s8 8s linear infinite;
  animation-delay: -11200ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s8 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(665deg);
  }
}
svg.star5:nth-child(9) {
  top: 85%;
  animation: s9 8s linear infinite;
  animation-delay: -12600ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s9 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(650deg);
  }
}
svg.star5:nth-child(10) {
  top: 42%;
  animation: s10 8s linear infinite;
  animation-delay: -14000ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s10 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(295deg);
  }
}
svg.star5:nth-child(11) {
  top: 23%;
  animation: s11 8s linear infinite;
  animation-delay: -15400ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s11 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(478deg);
  }
}
svg.star5:nth-child(12) {
  top: 92%;
  animation: s12 8s linear infinite;
  animation-delay: -16800ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s12 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(716deg);
  }
}
svg.star5:nth-child(13) {
  top: 30%;
  animation: s13 8s linear infinite;
  animation-delay: -18200ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s13 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(402deg);
  }
}
svg.star5:nth-child(14) {
  top: 4%;
  animation: s14 8s linear infinite;
  animation-delay: -19600ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s14 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(804deg);
  }
}
svg.star5:nth-child(15) {
  top: 38%;
  animation: s15 8s linear infinite;
  animation-delay: -21000ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s15 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(584deg);
  }
}
svg.star5:nth-child(16) {
  top: 70%;
  animation: s16 8s linear infinite;
  animation-delay: -22400ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s16 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(178deg);
  }
}
svg.star5:nth-child(17) {
  top: 52%;
  animation: s17 8s linear infinite;
  animation-delay: -23800ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s17 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(761deg);
  }
}
svg.star5:nth-child(18) {
  top: 33%;
  animation: s18 8s linear infinite;
  animation-delay: -25200ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s18 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(542deg);
  }
}
svg.star5:nth-child(19) {
  top: 44%;
  animation: s19 8s linear infinite;
  animation-delay: -26600ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s19 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(205deg);
  }
}
svg.star5:nth-child(20) {
  top: 95%;
  animation: s20 8s linear infinite;
  animation-delay: -28000ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s20 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(561deg);
  }
}
svg.star5:nth-child(21) {
  top: 53%;
  animation: s21 8s linear infinite;
  animation-delay: -29400ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s21 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(498deg);
  }
}
svg.star5:nth-child(22) {
  top: 40%;
  animation: s22 8s linear infinite;
  animation-delay: -30800ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s22 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(268deg);
  }
}
svg.star5:nth-child(23) {
  top: 84%;
  animation: s23 8s linear infinite;
  animation-delay: -32200ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s23 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(678deg);
  }
}
svg.star5:nth-child(24) {
  top: 76%;
  animation: s24 8s linear infinite;
  animation-delay: -33600ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s24 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(730deg);
  }
}
svg.star5:nth-child(25) {
  top: 87%;
  animation: s25 8s linear infinite;
  animation-delay: -35000ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s25 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(193deg);
  }
}
svg.star5:nth-child(26) {
  top: 46%;
  animation: s26 8s linear infinite;
  animation-delay: -36400ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s26 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(694deg);
  }
}
svg.star5:nth-child(27) {
  top: 55%;
  animation: s27 8s linear infinite;
  animation-delay: -37800ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s27 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(622deg);
  }
}
svg.star5:nth-child(28) {
  top: 76%;
  animation: s28 8s linear infinite;
  animation-delay: -39200ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s28 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(535deg);
  }
}
svg.star5:nth-child(29) {
  top: 73%;
  animation: s29 8s linear infinite;
  animation-delay: -40600ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s29 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(474deg);
  }
}
svg.star5:nth-child(30) {
  top: 93%;
  animation: s30 8s linear infinite;
  animation-delay: -42000ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s30 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(657deg);
  }
}
svg.star5:nth-child(31) {
  top: 34%;
  animation: s31 8s linear infinite;
  animation-delay: -43400ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s31 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(802deg);
  }
}
svg.star5:nth-child(32) {
  top: 70%;
  animation: s32 8s linear infinite;
  animation-delay: -44800ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s32 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(206deg);
  }
}
svg.star5:nth-child(33) {
  top: 99%;
  animation: s33 8s linear infinite;
  animation-delay: -46200ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s33 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(21deg);
  }
}
svg.star5:nth-child(34) {
  top: 96%;
  animation: s34 8s linear infinite;
  animation-delay: -47600ms;
  width: 30px;
  height: 30px;
  position: absolute;
  left: 2000px;
  overflow: hidden;
}
@keyframes s34 {
  0% {
    left: 2000px;
    transform: rotateZ(0deg);
  }
  100% {
    left: -10px;
    transform: rotateZ(425deg);
  }
}

svg.star7 {
  position: absolute;
  width: 20px;
  height: 20px;
}
svg.star7:nth-child(36) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 96%;
  animation: r36 5s linear infinite;
  animation-delay: -50400ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r36 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(37) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 18%;
  animation: r37 5s linear infinite;
  animation-delay: -51800ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r37 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(38) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 7%;
  animation: r38 5s linear infinite;
  animation-delay: -53200ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r38 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(39) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 98%;
  animation: r39 5s linear infinite;
  animation-delay: -54600ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r39 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(40) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 95%;
  animation: r40 5s linear infinite;
  animation-delay: -56000ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r40 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(41) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 37%;
  animation: r41 5s linear infinite;
  animation-delay: -57400ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r41 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(42) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 44%;
  animation: r42 5s linear infinite;
  animation-delay: -58800ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r42 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(43) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 44%;
  animation: r43 5s linear infinite;
  animation-delay: -60200ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r43 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(44) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 75%;
  animation: r44 5s linear infinite;
  animation-delay: -61600ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r44 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(45) {
  z-index: 1;
  overflow: hidden;
  width: 20px;
  height: 20px;
  top: 52%;
  animation: r45 5s linear infinite;
  animation-delay: -63000ms;
  width: 40px;
  height: 40px;
  opacity: 0.7;
}
@keyframes r45 {
  0% {
    left: 1940px;
  }
  100% {
    left: -20px;
  }
}
svg.star7:nth-child(46) {
  z-index: 1;
  overflow:.........完整代码请登录后点击上方下载按钮下载查看

网友评论0