CSS3连续旋转动画(就像加载日晷)

发布于 2024-08-28 08:02:58 字数 575 浏览 12 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

巾帼英雄 2024-09-04 08:02:58

这里的问题是,当您需要 -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.

这样的小城市 2024-09-04 08:02:58

您还可能会注意到一点滞后,因为 0deg 和 360deg 是同一个点,因此它会从点 1 绕一圈回到点 1。这确实微不足道,但要修复它,您所要做的就是将 360deg 更改为359deg

我的jsfiddle说明了你的动画:

#myImg {
    -webkit-animation: rotation 2s infinite linear;
}

@-webkit-keyframes rotation {
    from {-webkit-transform: rotate(0deg);}
    to   {-webkit-transform: rotate(359deg);}
}

另外,可能更类似于苹果加载图标的是动画转换灰色条纹的不透明度/颜色而不是旋转图标。

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:

#myImg {
    -webkit-animation: rotation 2s infinite linear;
}

@-webkit-keyframes rotation {
    from {-webkit-transform: rotate(0deg);}
    to   {-webkit-transform: rotate(359deg);}
}

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.

陌上青苔 2024-09-04 08:02:58

你可以像这样使用动画:

-webkit-animation: spin 1s infinite linear;

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

You could use animation like this:

-webkit-animation: spin 1s infinite linear;

@-webkit-keyframes spin {
    0%   {-webkit-transform: rotate(0deg)}
    100% {-webkit-transform: rotate(360deg)}
}
朱染 2024-09-04 08:02:58

你的代码看起来是正确的。我认为这与您使用 .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.

云朵有点甜 2024-09-04 08:02:58

我制作了一个小型库,让您可以轻松使用没有图像的 throbber。

它使用 CSS3,但如果浏览器不支持它,则会退回到 JavaScript。

// First argument is a reference to a container element in which you
// wish to add a throbber to.
// Second argument is the duration in which you want the throbber to
// complete one full circle.
var throbber = throbbage(document.getElementById("container"), 1000);

// Start the throbber.
throbber.play();

// Pause the throbber.
throbber.pause();

示例

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.

// First argument is a reference to a container element in which you
// wish to add a throbber to.
// Second argument is the duration in which you want the throbber to
// complete one full circle.
var throbber = throbbage(document.getElementById("container"), 1000);

// Start the throbber.
throbber.play();

// Pause the throbber.
throbber.pause();

Example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文