在月球上停止css关键帧翻转动画,如月相

时间:2018-10-08 05:00:23

标签: html css animation keyframe

如何在月球上停止CSS关键帧翻转动画

我有月光照度,我想以照度为基础在月球上显示月光。月亮的照度为百分之一百(1-100%),月光应为月球的1-100%

对于exe,当月亮照度为10%,月亮上的白色(月亮亮度)应为10%时

此处是月亮的html和CSS代码

.moon {
  width: 100px;
  height: 100px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  background-color: #fff;
  -webkit-transform: translateZ(0);
          transform: translateZ(0);
}
.moon::before {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  background-color: #222;
  width: 50%;
  height: 100%;
  -webkit-animation: flip 2s 1s steps(2) infinite alternate;
          animation: flip 2s 1s steps(2) infinite alternate;
}

.disc {
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  width: 100%;
  height: 100%;
  -webkit-animation: rotate 4s linear infinite;
          animation: rotate 4s linear infinite;
}
.disc::before, .disc::after {
  content: " ";
  display: block;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  transition: -webkit-transform 4s;
  transition: transform 4s;
  transition: transform 4s, -webkit-transform 4s;
  position: absolute;
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
}
.disc::before {
  background-color: #222;
}
.disc::after {
  background-color: #fff;
  -webkit-transform: rotateY(180deg);
          transform: rotateY(180deg);
}

@-webkit-keyframes rotate {
  0% {
    -webkit-transform: rotateY(0deg);
            transform: rotateY(0deg);
  }
  100% {
    -webkit-transform: rotateY(360deg);
            transform: rotateY(360deg);
  }
}

@keyframes rotate {
  0% {
    -webkit-transform: rotateY(0deg);
            transform: rotateY(0deg);
  }
  100% {
    -webkit-transform: rotateY(360deg);
            transform: rotateY(360deg);
  }
}
@-webkit-keyframes flip {
  0% {
    left: 0;
  }
  100% {
    left: 100%;
  }
}
@keyframes flip {
  0% {
    left: 0;
  }
  100% {
    left: 100%;
  }
}
html, body {
  height: 100%;
  width: 100%;
}

body {
  background-color: #222222;
  text-align: center;
  color: #ffffff;
  font-family: 'Fira Mono', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
  letter-spacing: .1em;
}
<div class="moon">
  <div class="disc"></div>
</div>

1 个答案:

答案 0 :(得分:0)

我认为您要获得的是希望动画一次运行然后停止。如果是这样,则应稍微更改动画。具体来说,您需要:

  1. animation-fill-mode的{​​{1}}设置为.disc
  2. forwards的{​​{1}}设置为animation-iteration-count
  3. .disc关键帧项更改为仅旋转1度,而不是360度。

Here's a codepen显示完整的解决方案。为了清楚/简洁起见,我删除了一些不必要的动画,并删除了未添加前缀的CSS。