纯css实现夜晚的列车驶入效果

代码语言:html

所属分类:布局界面

代码描述:纯css实现夜晚的列车驶入效果

代码标签: 夜晚 列车 驶入 效果

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


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
* {
  outline: none;
  box-sizing: border-box;
}

:root {
  --body-color: #dedddf;
  --night-color: #1f1c1f;
}

html {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  background-color: var(--body-color);
  display: -webkit-box;
  display: flex;
  -webkit-box-align: center;
          align-items: center;
  height: 100vh;
  -webkit-box-pack: center;
          justify-content: center;
}

.container {
  position: relative;
  width: 500px;
  height: 456px;
  display: -webkit-box;
  display: flex;
  -webkit-box-pack: center;
          justify-content: center;
  -webkit-box-align: center;
          align-items: center;
}

.container-wrapper {
  position: absolute;
  -webkit-clip-path: polygon(37% 0, 65% 0, 100% 100%, 0% 100%);
          clip-path: polygon(37% 0, 65% 0, 100% 100%, 0% 100%);
  width: 500px;
  height: 450px;
  background-color: var(--night-color);
}

.star-container {
  width: 100%;
  height: 100%;
  display: -webkit-box;
  display: flex;
  position: absolute;
  z-index: 1;
}

.stars {
  flex-shrink: 0;
  width: 100%;
  height: 100%;
  position: relative;
  will-change: transform;
  -webkit-animation: infinity-loop 5s infinite linear .1s both;
          animation: infinity-loop 5s infinite linear .1s both;
}

.moon {
  position: absolute;
  width: 45px;
  height: 45px;
  background-color: var(--night-color);
  top: 100px;
  left: 180px;
  border-radius: 50%;
  box-shadow: -11px -11px 0 0 var(--body-color) inset;
  -webkit-animation: moon 20s infinite linear .1s both;
          animation: moon 20s infinite linear .1s both;
  z-index: 2;
}

.star {
  position: absolute;
  background-color: var(--body-color);
  z-index: 9;
}
.star:nth-child(1) {
  right: 200px;
  top: 60px;
  border-radius: 50%;
  width: 5px;
  height: 5px;
}
.star:nth-child(2) {
  right: 90px;
  top: 40px;
  border-left: 1px solid var(--body-color);
  height: 10px;
}
.star:nth-child(2):before {
  right: -5px;
  top: 4px;
  content: "";
  position: absolute;
  border-bottom: 1px solid var(--body-color);
  width: 10px;
}
.star:nth-child(3) {
  right: 314px;
  top: 70px;
  border-left: 2px solid var(--body-color);
  height: 13px;
}
.star:nth-child(3):before {
  right: -6px;
  top: 5px;
  content: "";
  position: absolute;
  border-bottom: 2px solid var(--body-color);
  width: 13px;
}
.star:nth-child(4) {
  right: 220px;
  top: 120px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.star:nth-child(5) {
  right: 360px;
  top: 130px;
  border-radius: 50%;
  width: 4px;
  height: 4px;
}
.star:nth-child(6) {
  right: 245px;
  top: 70px;
  border-radius: 50%;
  width: 4px;
  height: 4px;
}
.star:nth-child(7) {
  right: 160px;
  top: 100px;
  border-left: 2px solid var(--body-color);
  height: 15px;
}
.star:nth-child(7):before {
  right: -7px;
  top: 6px;
  content: "";
  position: absolute;
  border-bottom: 2px solid var(--body-color);
  width: 15px;
}
.star:nth-child(8) {
  right: 200px;
  top: 150px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
}
.star:nth-child(9) {
  right: 290px;
  top: 160px;
  border-left: 1px solid var(--body-color);
  height: 9px;
}
.star:nth-child(9):before {
  right: -4px;
  top: 4px;
  content: "";
  position: absolute;
  border-bottom: 1px solid var(--body-color);
  width: 8px;
}
.star:nth-child(10) {
  right: 100px;
  top: 100px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
}
.star:nth-child(11) {
  right: 120px;
  top: 150px;
  border-left: 1px solid var(--body-color);
  height: 9px;
}
.star:nth-child(11):before {
  right: -4px;
  top: 4px;
  content: "";
  position: absolute;
  border-bottom: 1px solid var(--body-color);
  width: 8px;
}
.star:nth-child(12) {
  right: 380px;
  top: 60px;
  border-left: 1px solid var(--body-color);
  height: 9px;
}
.star:nth-child(12):before {
  right: -4px;
  top: 4px;
  content: "";
  position: absolute;
  border-bottom: 1px solid var(--body-color);
  width: 8px;
}
.star:nth-child(13) {
  right: 440px;
  top: 80px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.star:nth-child(14) {
  right: 10px;
  top: 60px;
  border-left: 1px solid var(--body-color);
  height: 9px;
}
.star:nth-child(14):before {
  right: -4px;
  top: 4px;
  content: "";
  position: absolute;
  border-bottom: 1px solid var(--body-color);
  width: 8px;
}
.star:nth-child(15) {
  right: 0px;
  top: 120px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.star:nth-child(16) {
  right: 450px;
  top: 140px;
  border-left: 2px solid var(--body-color);
  height: 15px;
}
.star:nth-child(16):before {
  right: -7px;
  top: 6px;
  content: "";
  position: absolute;
  border-bottom: 2px solid var(--body-color);
  width: 15px;
}
.star:nth-child(17) {
  right: 60px;
  top: 120px;
  border-left: 1px solid var(--body-color);
  height: 10px;
}
.star:nth-child(17):before {
  right: -5px;
  top: 4px;
  content: "";
  position: absolute;
  border-bottom: 1px solid var(--body-color);
  width: 10px;
}

.container-back {
  position: absolute;
  -webkit-clip-path: polygon(37% 0, 65% 0, 100% 100%, 0% 100%);
          clip-path: polygon(37% 0, 65% 0, 100% 100%, 0% 100%);
  width: 508px;
  height: 456px;
  background-color: var(--night-color);
}

.lamb {
  position: absolute;
  top: -35px;
  left: 50%;
  -webkit-transform: translate(-43%);
          transform: translate(-43%);
  width: 66px;
  height: 66px;
  background-color: var(--body-color);
  z-index: 1;
  border-radius: 50%;
}

.chandelier {
  position: absolute;
  top: -35px;
  left: 50%;
  -webkit-transform: translateX(-47%);
          transform: translateX(-47%);
  width: 150px;
  height: 32px;
  z-index: 2;
  border-radius: 40px 40px 0 0;
}

.chandelier-case {
  background-color: #1e1c1e;
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 100%;
  border-radius: 40px 40px 0 0;
}

.chandelier-detail {
  position: absolute;
  width: 95px;
  height: 10px;
  border: 2px solid #1e1c1e;
}
.chandelier-detail:nth-child(1) {
  right: 29px;
  bottom: 32px;
}
.chandelier-detail:nth-child(2) {
  right: 36px;
  bottom: 40px;
  width: 80px;
}
.chandelier-detail:nth-child(3) {
  right: 46px;
  bottom: 48px;
  height: 17px;
  width: 60px;
  background-color: #1e1c1e;
}
.chandelier-detail:nth-child(4) {
  right: 61px;
  bottom: 62px;
  width: 30px;
  height: 15px;
}

.line {
  position: absolute;
  border: 1px solid #1e1c1e;
  height: 60px;
  right: 50%;
  top: -105px;
}

.night {
  background-color: var(--night-color);
  height: 400px;
  display: -webkit-box;
  display: flex;
  -webkit-box-align: end;
          align-items: flex-end;
  flex-shrink: 0;
  -webkit-animation: infinity-loop 1.8s infinite linear .1s both;
          animation: infinity-loop 1.8s infinite linear .1s both;
  will-change: transform;
}

.night-wrapper {
  display: -webkit-box;
  display: flex;
}

.train {
  position: relative;
  bottom: 8px;
  width: 520px;
  height: 200px;
  z-index: 4;
  flex-shrink: 0;
}

.train-link {
  position: absolute;
  width: 20px;
  height: 141px;
  border: 2px solid var(--night-color);
  right: 0;
  bottom: 38px;
  background-color: var(--body-color);
}
.train-link:before {
  content: "";
  position: absolute;
  border: 1px solid var(--night-color);
  height: 141px;
  right: calc(50% - 1px);
}

.train-coach {
  position: absolute;
  background-color: var(--body-color);
  width: 500px;
  height: 175px;
  border-radius: 30px 30px 0 0;
  border-bottom: 2px solid var(--night-color);
}
.train-coach:before {
  content: "";
  position: absolute;
  width: 460px;
  height: 2px;
  background-color: var(--night-color);
  top: 10px;
  right: 20px;
}
.train-coach:after {
  content: "";
  position: absolute;
  height: 2px;
  width: 100%;
  background-color: var(--night-color);
  bottom: 7px;
  left: 0;
}

.train-mid {
  border: 1px solid var(--night-color);
  width: 500px;
  position: absolute;
  top: 20px;
}

.window {
  position: absolute;
  background-color: var(--night-color);
  width: 72px;
  height: 54px;
  border-radius: 10px;
}
.window:nth-child(1) {
  left: 25px;
  top: 25px;
}
.window:nth-child(1):before {
  content: "";
  position: absolute;
  height: 2px;
  width: 162px;
  background-color: var(--night-color);
  top: 80px;
  left: 0;
  box-shadow: 0 12px 0 0px;
}
.window:nth-child(2) {
  left: 112px;
  top: 25px;
}
.window:nth-child(3) {
  left: 308px;
  top: 25px;
}
.window:nth-child(3):before {
  content: "";
  position: absolute;
  height: 2px;
  width: 162px;
  background-color: var(--night-color);
  top: 80px;
  left: 0;
  box-shadow: 0 12px 0 0px;
}
.window:nth-child(4) {
  left: 395px;
  top: 25px;
}

.window-line {
  position: absolute;
  border: 0.2px solid var(--body-color);
  width: 80px;
  top: 20px;
}

.door {
  border: 2px solid var(--night-color);
  position: absolute;
  bottom: -2px;
  height: 125px;
  width: 72px;
  left: calc(50% + 2px);
  -webkit-transform: translatex(-50%);
          transform: translatex(-50%);
  border-radius: 10px 10px 0 0;
}
.door:before {
  content: "";
  position: absolute;
  border: 1px solid var(--night-color);
  height: 92%;
  left: calc(50% - 1px);
}

.roller {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background-color: var(--body-color);
  bottom: -30px;
  z-index: -1;
}
.roller:before {
  content: "";
  position: absolute;
  width: 34px;
  height: 34px;
  border: 2px solid var(--night-color);
  border-radius: 50%;
  right: 8px;
  bottom: 8px;
}
.roller:nth-child(1) {
  left: 20px;
}
.roller:nth-child(1):after {
  content: "";
  position: absolute;
  background-color: var(--body-color);
  width: 61px;
  height: 15px;
  bottom: 20px;
  left: calc(100% + 3px);
  border-radius: 0 0 10px 10px;
}
.roller:nth-child(2) {
  left: 140px;
}
.roller:nth-child(3) {
  right: 140px;
}
.roller:nth-child(3):after {
  content: ".........完整代码请登录后点击上方下载按钮下载查看

网友评论0