CSS3连续旋转动画(就像加载日晷)
我正在尝试使用 PNG 和 CSS3 动画来复制 Apple 风格的活动指示器(日晷加载图标)。我让图像旋转并连续进行,但动画完成后在进行下一次旋转之前似乎有延迟。
@-webkit-keyframes rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#loading img
{
-webkit-animation-name: rotate;
-webkit-animation-duration: 0.5s;
-webkit-animation-iteration-count: infinite;
-webkit-transition-timing-function: linear;
}
我尝试过更改动画持续时间,但没有什么区别,如果你直接放慢速度,比如说 5 秒,那么在第一次旋转之后,在再次旋转之前会有一个暂停,这一点会更明显。我想摆脱的正是这种停顿。
非常感谢任何帮助,谢谢。
I am trying to replicate an Apple style activity indicator (sundial loading icon) by using a PNG and CSS3 animation. I have the image rotating and doing it continuously, but there seems to be a delay after the animation has finished before it does the next rotation.
@-webkit-keyframes rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#loading img
{
-webkit-animation-name: rotate;
-webkit-animation-duration: 0.5s;
-webkit-animation-iteration-count: infinite;
-webkit-transition-timing-function: linear;
}
I have tried changing the animation duration but it makes no difference, if you slow it right down say 5s its just more apparent that after the first rotation there is a pause before it rotates again. It's this pause I want to get rid of.
Any help is much appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这里的问题是,当您需要
-webkit-ANIMATION-timing-function
时,您却提供了-webkit-TRANSITION-timing-function
。您的 0 到 360 值将正常工作。Your issue here is that you've supplied a
-webkit-TRANSITION-timing-function
when you want a-webkit-ANIMATION-timing-function
. Your values of 0 to 360 will work properly.您还可能会注意到一点滞后,因为 0deg 和 360deg 是同一个点,因此它会从点 1 绕一圈回到点 1。这确实微不足道,但要修复它,您所要做的就是将 360deg 更改为359deg
我的jsfiddle说明了你的动画:
另外,可能更类似于苹果加载图标的是动画转换灰色条纹的不透明度/颜色而不是旋转图标。
You also might notice a little lag because 0deg and 360deg are the same spot, so it is going from spot 1 in a circle back to spot 1. It is really insignificant, but to fix it, all you have to do is change 360deg to 359deg
my jsfiddle illustrates your animation:
Also what might be more resemblant of the apple loading icon would be an animation that transitions the opacity/color of the stripes of gray instead of rotating the icon.
你可以像这样使用动画:
You could use animation like this:
如果您只是在寻找 webkit 版本,这很不错: http://s3 .amazonaws.com/37assets/svn/463-single_spinner.html 来自 http://37signals.com/svn/posts/2577-loading-spinner-animation-using-css-and-webkit
If you're only looking for a webkit version this is nifty: http://s3.amazonaws.com/37assets/svn/463-single_spinner.html from http://37signals.com/svn/posts/2577-loading-spinner-animation-using-css-and-webkit
你的代码看起来是正确的。我认为这与您使用 .png 以及浏览器在旋转时重绘对象的方式效率低下有关,导致挂起(您在什么浏览器下测试?)
如果可能的话,将 .png 替换为其他内容本国的。
看; http://kilianvalkhof.com/2010/css-xhtml /css3-loading-spinners-without-images/
Chrome 使用这种方法不会让我停顿。
Your code seems correct. I would presume it is something to do with the fact you are using a .png and the way the browser redraws the object upon rotation is inefficient, causing the hang (what browser are you testing under?)
If possible replace the .png with something native.
see; http://kilianvalkhof.com/2010/css-xhtml/css3-loading-spinners-without-images/
Chrome gives me no pauses using this method.
我制作了一个小型库,让您可以轻松使用没有图像的 throbber。
它使用 CSS3,但如果浏览器不支持它,则会退回到 JavaScript。
示例。
I made a small library that lets you easily use a throbber without images.
It uses CSS3 but falls back onto JavaScript if the browser doesn't support it.
Example.