【问题标题】:Why is the spinner not spinning/rotating?为什么微调器不旋转/旋转?
【发布时间】:2016-02-15 14:13:14
【问题描述】:

我创建了一个锚链接按钮,当我单击处于:focus 状态的按钮时,我想在其中显示 Spinner 动画。我正在使用 Font Awesome 来显示动画,但是当我单击按钮时,微调器动画不起作用。

注意:我这里不想用 JavaScript 只想用 Pure CSS

这里是 CodePen 链接https://codepen.io/rhulkashyap/pen/vLPNdQ

@import url(https://fonts.googleapis.com/css?family=Titillium+Web);
 body {
  font-family: 'Titillium Web', sans-serif;
  text-align: center;
}
#button {
  padding: 15px;
  background-color: green;
  color: #fff;
  text-decoration: none;
  border-radius: 5px;
  width: 300px;
  display: inline-block;
  text-align: center;
  font-size: 25px;
  -webkit-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}
#button:before {
  content: "\f090";
  font-family: FontAwesome;
  margin-right: 5px;
}
#button:focus {
  background-color: #02b402;
}
#button:focus:before {
  content: "\f1ce";
  -webkit-animation: spin .8s ease infinite;
  animation: spin .8s ease infinite;
}
@-webkit-keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
@keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<h2> Click Here</h2>
<a id="button" href="javascript:void(0)">Enter In</a>

【问题讨论】:

  • 它似乎工作正常(Chrome)。您使用的是什么浏览器,不工作是什么意思?
  • 我使用的是 Firefox 开发者版

标签: html css css-animations css-transforms


【解决方案1】:

转换应该只适用于块级元素(包括inline-block)。使伪元素为display:inline-block 使动画工作。

在对问题发表评论后,我确实看到该动画在 Chrome v50 (dev-m) 中也无法在 Chrome v43 中运行。所以,目前的行为似乎是一致的

@import url(https://fonts.googleapis.com/css?family=Titillium+Web);
 body {
  font-family: 'Titillium Web', sans-serif;
  text-align: center;
}
#button {
  padding: 15px;
  background-color: green;
  color: #fff;
  text-decoration: none;
  border-radius: 5px;
  width: 300px;
  display: inline-block;
  text-align: center;
  font-size: 25px;
  -webkit-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}
#button:before {
  display: inline-block;
  content: "\f090";
  font-family: FontAwesome;
  margin-right: 5px;
}
#button:focus {
  background-color: #02b402;
}
#button:focus:before {
  content: "\f1ce";
  -webkit-animation: spin .8s ease infinite;
  animation: spin .8s ease infinite;
}
@-webkit-keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
@keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<h2> Click Here</h2>
<a id="button" href="javascript:void(0)">Enter In</a>

【讨论】:

  • @ketan:对不起,我没听懂你。如果您的意思是 transform@-webkit-keyframes 中的存在,那么它是必需的。有旧版本的 Chrome 支持不带前缀但不支持关键帧的转换(我认为甚至可以达到 v38 或其他内容)。反之则不是必需的。
  • 再想一想,我认为@-webkit-keyframes 中不应该需要不带前缀的transform,因为WebKit 应该能够在不带前缀的-webkit-transform 不存在时使用。但我似乎仍然记得早些时候遇到过这个问题。无论如何,对于最新版本,标准版本就足够了:)
猜你喜欢
  • 1970-01-01
  • 2016-11-02
  • 1970-01-01
  • 1970-01-01
  • 2016-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-02
相关资源
最近更新 更多