欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
  源代码下载
 
  https://github.com/comehope/front-end-daily-challenges
 
  代码解读
 
  定义dom,容器中包含6个元素:
 
  <divclass="wheel">
 
  <span></span>
 
  <span></span>
 
  <span></span>
 
  <span></span>
 
  <span></span>
 
  <span></span>
 
  </div>
 
  居中显示:
 
  body{
 
  margin:0;
 
  height:100vh;
 
  display:flex;
 
  align-items:center;
 
  justify-content:center;
 
  background-image:linear-gradient(#555,#222);
 
  }
 
  画出轮圈:
 
  .wheel{
 
  width:9em;
 
  height:9em;
 
  font-size:25px;
 
  border:0.4emsolid#777;
 
  border-radius:50%;
 
  box-shadow:0000.5em#111;
 
  }
 
  定义辐条的样式:
 
  .wheel{
 
  display:flex;
 
  align-items:center;
 
  justify-content:center;
 
  }
 
  .wheelspan{
 
  position:absolute;
 
  width:8em;
 
  height:1em;
 
  border:0.1emsolid;
 
  border-color:#ccctransparent;
 
  }
 
  定义变量,画出多根幅条:
 
  
 
  .wheelspan{
 
  transform:rotate(calc((var(--n)-1)*30deg));
 
  }
 
  .wheelspan:nth-child(1){
 
  --n:1;
 
  }
 
  .wheelspan:nth-child(2){
 
  --n:2;
 
  }
 
  .wheelspan:nth-child(3){
 
  --n:3;
 
  }
 
  .wheelspan:nth-child(4){
 
  --n:4;
 
  }
 
  .wheelspan:nth-child(5){
 
  --n:5;
 
  }
 
  .wheelspan:nth-child(6){
 
  --n:6;
 
  }
 
  让车轮转动起来:
 
  .wheelspan{
 
  animation:run4slinearinfinite;
 
  }
 
  @keyframesrun{
 
  to{
 
  transform:rotate(calc((var(--n)-1)*30deg+360deg));
 
  }
 
  }
 
  用伪元素画出地面上的线条:
 
  
 
  .wheel{
 
  position:relative;
 
  }
 
  .wheel::before{
 
  content:'';
 
  position:absolute;
 
  width:15em;
 
  height:0.2em;
 
  top:11em;
 
  background-image:linear-gradient(
 
  toright,
 
  silver0,silver4em,
 
  transparent4em,transparent5em,
 
  silver5em,silver10em,
 
  transparent10em,transparent12em,
 
  silver12em,silver14em,
 
  transparent14em,transparent15em
 
  );
 
  }
 
  最后,让地面上的线条动起来,形成车轮向前走的效果:
 
  .wheel::before{
 
  background-position:15em;
 
  animation:run26slinearinfinite;
 
  }
 
  @keyframesrun2{
 
  to{
 
  background-position:-15em;
 
  }
 
  }







本文转载自中文网
 

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/css3-style/c55455.shtml