夜空中繁星露营地场景特效

css3绘制夜晚满天繁星,流星滑过,山上露营帐篷动画场景特效,更好的欢迎分享
在这里插入图片描述
HTML代码

<div class="canvas">
  <div class="sky"></div>
  <div class="stars">
    <div class="falling-stars">
      <div class="star-fall"></div>
      <div class="star-fall"></div>
      <div class="star-fall"></div>
      <div class="star-fall"></div>
    </div>
    <div class="small-stars">
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
    </div>
    <div class="medium-stars">
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
      <div class="star"></div>
    </div>
  </div>
  <div class="mountains"></div>
  <div class="sun"></div>
  <div class="glowflies">
    <div class="glowfly"></div>
    <div class="glowfly"></div>
    <div class="glowfly"></div>
    <div class="glowfly"></div>
    <div class="glowfly"></div>
    <div class="glowfly"></div>
    <div class="glowfly"></div>
    <div class="glowfly"></div>
  </div>
  <div class="tent">
    <div class="upper"></div>
    <div class="bottom"></div>
    <div class="shadow"></div>
    <div class="line"></div>
    <div class="door"></div>
    <div class="door-part"></div>
    <div class="door-part two"></div>
  </div>
  <div class="trees">
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
    <div class="tree"></div>
  </div>
  <div class="floor"></div>
</div>

CSS代码

:root {
  --sky: #010641;
  --gradient-bg: linear-gradient(180deg, rgba(97,77,102,1) 0%, rgba(1,6,65,1) 83%);
  --tree-a: #0e134f;
  --tree-b: #6c5665;
  --mountain: linear-gradient(180deg, rgba(90,80,121,1) 0%, rgba(34,40,104,1) 83%);
  --shadow: #020836;
  --sun: #fdc3aa;
  --growfly: #a57d7a;
  --light: #f9b12f;
  --tent-a: #4c5c9a;
  --tent-b: #252b65;
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  display: -webkit-box;
  display: flex;
  -webkit-box-pack: center;
          justify-content: center;
  -webkit-box-align: center;
          align-items: center;
  overflow: hidden;
}

body {
  background-color: var(--sky);
}

.canvas {
  position: relative;
  border-radius: 50%;
  width: 600px;
  height: 600px;
  background-color: var(--sky);
  overflow: hidden;
  flex-shrink: 0;
}

.floor {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 180px;
  background: var(--gradient-bg);
  z-index: 2;
}

.tree {
  position: absolute;
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 280px solid var(--tree-a);
  z-index: 3;
}
.tree:before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-bottom: 280px solid var(--shadow);
  border-left: 50px solid transparent;
  -webkit-transform: translatex(-100%);
          transform: translatex(-100%);
}
.tree:after {
  position: absolute;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-top: 180px solid var(--shadow);
  bottom: -460px;
  left: -102px;
  z-index: 6;
}
.tree:first-child {
  left: 20px;
  bottom: 160px;
  z-index: 4;
}
.tree:first-child:after {
  content: '';
  bottom: -460px;
  left: -122px;
  z-index: 6;
  -webkit-transform: skew(-32deg);
          transform: skew(-32deg);
}
.tree:nth-child(2) {
  left: 80px;
  bottom: 140px;
  -webkit-transform: scale(0.8);
          transform: scale(0.8);
}
.tree:nth-child(2):after {
  content: '';
  bottom: -460px;
  left: -102px;
  z-index: 5;
  -webkit-transform: skew(-30deg);
          transform: skew(-30deg);
}
.tree:nth-child(3) {
  left: 420px;
  bottom: 40px;
  -webkit-transform: scale(1.6);
          transform: scale(1.6);
  z-index: 6;
}
.tree:nth-child(4) {
  left: 490px;
  bottom: 140px;
  -webkit-transform: scale(1.4);
          transform: scale(1.4);
}
.tree:nth-child(5) {
  left: 490px;
  bottom: 140px;
  -webkit-transform: scale(1.4);
          transform: scale(1.4);
}

.mountains {
  position: absolute;
  width: 280px;
  height: 120px;
  background: var(--mountain);
  left: 40px;
  bottom: 120px;
  border-radius: 120%;
  box-shadow: 260px 0 0 #222868;
  z-index: 1;
}

.sun {
  position: absolute;
  border-radius: 50%;
  width: 240px;
  height: 240px;
  background-color: var(--sun);
  -webkit-transform: translatex(-50%);
          transform: translatex(-50%);
  left: 50%;
  bottom: 10px;
  box-shadow: 0 0 200px var(--sun);
}

.stars {
  position: absolute;
  z-index: 1;
  width: 100%;
  height: 400px;
}

.star {
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0px 0px 6px 0px rgba(255, 255, 255, 0.8);
}

.small-stars .star {
  position: absolute;
  width: 3px;
  height: 3px;
}
.small-stars .star:nth-child(2n) {
  opacity: 0;
  -webkit-animation: star-blink 1.2s linear infinite alternate;
          animation: star-blink 1.2s linear infinite alternate;
}
.small-stars .star:nth-child(1) {
  left: 210px;
  bottom: 50px;
}
.small-stars .star:nth-child(2) {
  left: 400px;
  bottom: 40px;
}
.small-stars .star:nth-child(3) {
  left: 420px;
  bottom: 120px;
}
.small-stars .star:nth-child(4) {
  left: 140px;
  bottom: 250px;
}
.small-stars .star:nth-child(5) {
  left: 400px;
  bottom: 300px;
}
.small-stars .star:nth-child(6) {
  left: 170px;
  bottom: 80px;
}
.small-stars .star:nth-child(7) {
  left: 200px;
  bottom: 360px;
  -webkit-animation-delay: .2s;
          animation-delay: .2s;
}
.small-stars .star:nth-child(8) {
  left: 250px;
  bottom: 320px;
}
.small-stars .star:nth-child(9) {
  left: 300px;
  bottom: 340px;
}
.small-stars .star:nth-child(10) {
  left: 130px;
  bottom: 320px;
  -webkit-animation-delay: .5s;
          animation-delay: .5s;
}
.small-stars .star:nth-child(11) {
  left: 230px;
  bottom: 330px;
  -webkit-animation-delay: 7s;
          animation-delay: 7s;
}
.small-stars .star:nth-child(12) {
  left: 300px;
  bottom: 360px;
  -webkit-animation-delay: .3s;
          animation-delay: .3s;
}
@-webkit-keyframes star-blink {
  50% {
    width: 3px;
    height: 3px;
    opacity: 1;
  }
}
@keyframes star-blink {
  50% {
    width: 3px;
    height: 3px;
    opacity: 1;
  }
}
.medium-stars .star {
  position: absolute;
  width: 3px;
  height: 3px;
  opacity: 0;
  -webkit-animation: star-blink 1.2s ease-in infinite alternate;
          animation: star-blink 1.2s ease-in infinite alternate;
}
.medium-stars .star:nth-child(1) {
  left: 300px;
  bottom: 50px;
}
.medium-stars .star:nth-child(2) {
  left: 400px;
  bottom: 40px;
  -webkit-animation-delay: .4s;
          animation-delay: .4s;
}
.medium-stars .star:nth-child(3) {
  left: 330px;
  bottom: 300px;
  -webkit-animation-delay: .2s;
          animation-delay: .2s;
}
.medium-stars .star:nth-child(4) {
  left: 460px;
  bottom: 300px;
  -webkit-animation-delay: .9s;
          animation-delay: .9s;
}
.medium-stars .star:nth-child(5) {
  left: 300px;
  bottom: 150px;
  -webkit-animation-delay: 1.2s;
          animation-delay: 1.2s;
}
.medium-stars .star:nth-child(6) {
  left: 440px;
  bottom: 120px;
  -webkit-animation-delay: 1s;
          animation-delay: 1s;
}
.medium-stars .star:nth-child(7) {
  left: 200px;
  bottom: 140px;
  -webkit-animation-delay: .8s;
          animation-delay: .8s;
}
.medium-stars .star:nth-child(8) {
  left: 30px;
  bottom: 480px;
  -webkit-animation-delay: .3s;
          animation-delay: .3s;
}
.medium-stars .star:nth-child(9) {
  left: 460px;
  bottom: 400px;
  -webkit-animation-delay: 1.2s;
          animation-delay: 1.2s;
}
.medium-stars .star:nth-child(10) {
  left: 150px;
  bottom: 10px;
  -webkit-animation-delay: 1s;
          animation-delay: 1s;
}
.medium-stars .star:nth-child(11) {
  left: 420px;
  bottom: 450px;
  -webkit-animation-delay: 1.2s;
          animation-delay: 1.2s;
}
.medium-stars .star:nth-child(12) {
  left: 340px;
  bottom: 180px;
  -webkit-animation-delay: 1.1s;
          animation-delay: 1.1s;
}
@keyframes star-blink {
  50% {
    width: 4px;
    height: 4px;
    opacity: 1;
  }
}
.star-fall {
  position: relative;
  border-radius: 2px;
  width: 80px;
  height: 2px;
  overflow: hidden;
  -webkit-transform: rotate(-20deg);
          transform: rotate(-20deg);
}
.star-fall:after {
  content: "";
  position: absolute;
  width: 50px;
  height: 2px;
  background: -webkit-gradient(linear, right top, left top, from(rgba(0, 0, 0, 0)), to(rgba(255, 255, 255, 0.4)));
  background: linear-gradient(to left, rgba(0, 0, 0, 0) 0%, rgba(255, 255, 255, 0.4) 100%);
  left: 100%;
  -webkit-animation: star-fall 3.6s linear infinite;
          animation: star-fall 3.6s linear infinite;
}

.star-fall:nth-child(1) {
  left: 80px;
  bottom: -100px;
}
.star-fall:nth-child(1):after {
  -webkit-animation-delay: 2.4s;
          animation-delay: 2.4s;
}

.star-fall:nth-child(2) {
  left: 200px;
  bottom: -200px;
}
.star-fall:nth-child(2):after {
  -webkit-animation-delay: 2s;
          animation-delay: 2s;
}

.star-fall:nth-child(3) {
  left: 430px;
  bottom: -50px;
}
.star-fall:nth-child(3):after {
  -webkit-animation-delay: 3.6s;
          animation-delay: 3.6s;
}

.star-fall:nth-child(4) {
  left: 400px;
  bottom: 100px;
}
.star-fall:nth-child(4):after {
  -webkit-animation-delay: .2s;
          animation-delay: .2s;
}

@-webkit-keyframes star-fall {
  20% {
    left: -100%;
  }
  100% {
    left: -100%;
  }
}

@keyframes star-fall {
  20% {
    left: -100%;
  }
  100% {
    left: -100%;
  }
}
.glowfly {
  position: absolute;
  border-radius: 50%;
  background-color: var(--growfly);
  box-shadow: 0 0 14px var(--light);
  width: 8px;
  height: 8px;
  z-index: 8;
  -webkit-animation: fly 5s ease infinite alternate;
          animation: fly 5s ease infinite alternate;
}
.glowfly:first-child {
  left: 120px;
  bottom: 180px;
}
.glowfly:nth-child(1) {
  left: 240px;
  bottom: 180px;
  -webkit-animation-delay: .6s;
          animation-delay: .6s;
}
.glowfly:nth-child(2) {
  left: 340px;
  bottom: 160px;
  -webkit-animation-delay: .8s;
          animation-delay: .8s;
}
.glowfly:nth-child(3) {
  left: 110px;
  bottom: 110px;
  -webkit-animation-delay: .4s;
          animation-delay: .4s;
}
.glowfly:nth-child(4) {
  left: 40px;
  bottom: 60px;
  -webkit-animation-delay: 1s;
          animation-delay: 1s;
}
.glowfly:nth-child(5) {
  left: 80px;
  bottom: 240px;
  -webkit-animation-delay: 1.2s;
          animation-delay: 1.2s;
}
.glowfly:nth-child(6) {
  left: 480px;
  bottom: 140px;
  -webkit-animation-delay: .2s;
          animation-delay: .2s;
}
.glowfly:nth-child(7) {
  left: 400px;
  bottom: 30px;
  -webkit-animation-delay: .4s;
          animation-delay: .4s;
}
.glowfly:nth-child(8) {
  left: 400px;
  bottom: 200px;
  -webkit-animation-delay: .5s;
          animation-delay: .5s;
}

@-webkit-keyframes fly {
  0% {
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
  20% {
    -webkit-transform: translate(-8px, -8px);
            transform: translate(-8px, -8px);
  }
  60% {
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
  80% {
    -webkit-transform: translate(-6px, -6px);
            transform: translate(-6px, -6px);
  }
  100% {
    -webkit-transform: translate(-10px, -10px);
            transform: translate(-10px, -10px);
  }
}

@keyframes fly {
  0% {
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
  20% {
    -webkit-transform: translate(-8px, -8px);
            transform: translate(-8px, -8px);
  }
  60% {
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
  80% {
    -webkit-transform: translate(-6px, -6px);
            transform: translate(-6px, -6px);
  }
  100% {
    -webkit-transform: translate(-10px, -10px);
            transform: translate(-10px, -10px);
  }
}
.tent {
  position: absolute;
  -webkit-transform: translatex(-50%) scale(1.1);
          transform: translatex(-50%) scale(1.1);
  left: 50%;
  bottom: 120px;
  z-index: 6;
  width: 200px;
  height: 120px;
}
.tent:before, .tent:after {
  content: '';
  position: absolute;
  height: 50px;
  width: 2px;
  background-color: #e09d7d;
}
.tent:before {
  -webkit-transform: rotate(45deg);
          transform: rotate(45deg);
  left: -14px;
  bottom: 12px;
}
.tent:after {
  -webkit-transform: rotate(-45deg);
          transform: rotate(-45deg);
  right: -16px;
  bottom: 12px;
}

.upper {
  position: absolute;
  -webkit-clip-path: polygon(0% 80%, 50% 0%, 100% 80%, 51.5% 54.16%);
          clip-path: polygon(0% 80%, 50% 0%, 100% 80%, 51.5% 54.16%);
  height: 120px;
  width: 200px;
  background-color: var(--tent-a);
  -webkit-transform: translatex(-50%);
          transform: translatex(-50%);
  left: 50%;
  bottom: 30px;
}

.bottom {
  position: absolute;
  -webkit-clip-path: polygon(50% 0.74%, 99.83% 19.11%, 80.17% 38.15%, 18% 39.26%, -1px 19.85%);
          clip-path: polygon(50% 0.74%, 99.83% 19.11%, 80.17% 38.15%, 18% 39.26%, -1px 19.85%);
  height: 180px;
  width: 200px;
  bottom: 0;
  left: 0;
  background-color: var(--tent-b);
  -webkit-transform: translatex(-50%);
          transform: translatex(-50%);
  left: 50%;
  bottom: -91px;
}

.shadow {
  position: absolute;
  -webkit-clip-path: polygon(50% 0.74%, 99.83% 19.11%, 73.77% 28.68%, 27.76% 29.41%, -1px 19.85%);
          clip-path: polygon(50% 0.74%, 99.83% 19.11%, 73.77% 28.68%, 27.76% 29.41%, -1px 19.85%);
  height: 240px;
  width: 270px;
  background-color: var(--shadow);
  -webkit-transform: translatex(-50%) rotate(-180deg);
          transform: translatex(-50%) rotate(-180deg);
  left: 50%;
  bottom: -50px;
}

.line {
  position: absolute;
  height: 22px;
  width: 2px;
  background-color: var(--shadow);
  -webkit-transform: skew(-10deg);
          transform: skew(-10deg);
  left: -32px;
  bottom: -4px;
}

.door {
  position: absolute;
  -webkit-clip-path: polygon(50% 0%, 20% 100%, 88% 100%);
          clip-path: polygon(50% 0%, 20% 100%, 88% 100%);
  width: 70px;
  height: 88px;
  -webkit-transform: translatex(-50%);
          transform: translatex(-50%);
  left: 50%;
  bottom: 0;
  z-index: 7;
  background-color: var(--shadow);
}

.door-part {
  position: absolute;
  width: 12px;
  height: 80px;
  background-color: var(--tent-a);
  border-radius: 120%;
  left: calc(50% - 14px);
  bottom: 19px;
  z-index: 8;
  -webkit-transform: skew(-15deg);
          transform: skew(-15deg);
}
.door-part:before {
  content: '';
  position: absolute;
  -webkit-clip-path: polygon(50% 0%, 1px 71.55%, 50.5% 100.14%);
          clip-path: polygon(50% 0%, 1px 71.55%, 50.5% 100.14%);
  width: 30px;
  height: 80px;
  background-color: var(--tent-a);
  left: -10px;
}
.door-part.two {
  -webkit-transform: skew(15deg);
          transform: skew(15deg);
  left: calc(50% + 2px);
}
.door-part.two:before {
  -webkit-clip-path: polygon(50% 0%, 30px 69.27%, 59.34% 99%);
          clip-path: polygon(50% 0%, 30px 69.27%, 59.34% 99%);
}

@media screen and (max-width: 840px) {
  .canvas {
    -webkit-transform: scale(0.6);
            transform: scale(0.6);
  }
}
@media screen and (max-width: 520px) {
  .canvas {
    -webkit-transform: scale(0.5);
            transform: scale(0.5);
  }
}
@media screen and (max-height: 520px) {
  .canvas {
    -webkit-transform: scale(0.5);
            transform: scale(0.5);
  }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值