html - 用纯 CSS 制作速度计指针动画

标签 html css css-animations

我已经尽力了Jsfiddle .现在我想从左到右慢慢地为中心针点设置动画。我听说过 css 关键帧并尝试过。但是,它向左和向右移动。我没有得到预期的结果。如何仅使用纯 css 为这根针设置动画?

CSS

#logo
{
    display: inline-block;
    position: relative;
}
#logo .speedometer
{
    width: 80px;
    height: 80px;
    border-radius: 100%;
    border: 20px solid #000;
    border-right: 20px solid white;
    border-bottom: 20px solid white;
    -webkit-transform: rotate(45deg);
    display: inline-block;
}
#logo .needle
{
    width: 5px;
    height: 50px;
    background: #999999;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    border-top-left-radius: 100%;
    border-top-right-radius: 100%;
    display: inline-block;
    left: 57px;
    position: absolute;
    top: 10px;
}

HTML

<div id="logo">
    <span class="speedometer"></span>
    <span class="needle"></span>
</div>

最佳答案

演示 - http://jsfiddle.net/99oakz7w/2/

使用@keyframes

@-webkit-keyframes move {
  0% {
    transform: rotate(-90deg);
  }
  50% {
    transform: rotate(90deg);
  }
  100% {
    transform: rotate(-90deg);
  }
}

#logo {
  display: inline-block;
  position: relative;
}
#logo .speedometer {
  width: 80px;
  height: 80px;
  border-radius: 100%;
  border: 20px solid #000;
  border-right: 20px solid white;
  border-bottom: 20px solid white;
  -webkit-transform: rotate(45deg);
  display: inline-block;
}
#logo .needle {
  width: 5px;
  height: 50px;
  background: #999999;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  border-top-left-radius: 100%;
  border-top-right-radius: 100%;
  display: inline-block;
  left: 57px;
  position: absolute;
  top: 10px;
  -webkit-animation: move 5s infinite;
  transform: rotate(0deg);
  transform-origin: bottom;
}
@-webkit-keyframes move {
  0% {
    transform: rotate(-90deg);
  }
  50% {
    transform: rotate(90deg);
  }
  100% {
    transform: rotate(-90deg);
  }
}
<div id="logo">	<span class="speedometer"></span>
  <span class="needle"></span>

</div>

关于html - 用纯 CSS 制作速度计指针动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26814639/

相关文章:

css - Glyphicon 不会完全隐藏在 CSS3 悬停动画上

html - 用于在两种状态之间切换的 CSS 动画

javascript - 页面加载时隐藏菜单,onclick按钮显示菜单,第一次单击显示,第二次单击隐藏,就像 Angular 4.0中的切换一样

css - 将 img、span 和 div 与底部边框对齐

.net - 网站/Web应用程序体系结构建议

html - 在 IE11 中转换旋转

html - 悬停时的背景图像

html - 不同缩放级别的元素之间的间隙

html - 不同尺寸div的网格布局(ul)

css - 为什么这段 CSS 代码只能在 Chrome 中运行?