css连续旋转
While building the React Handbook landing page, I had to search how to rotate an image. I wanted to rotate an SVG image, but this works for any image type. Or any HTML element, actually.
在构建React Handbook登陆页面时,我不得不搜索如何旋转图像。 我想旋转SVG图像,但这适用于任何图像类型。 实际上是任何HTML元素。
Add this CSS instruction to the element you want to rotate:
将此CSS指令添加到要旋转的元素中:
animation: rotation 2s infinite linear;
You can also choose to add a rotate
class to an element, instead of targeting it directly:
您还可以选择将rotate
类添加到元素,而不是直接定位它:
.rotate {
animation: rotation 2s infinite linear;
}
tweak the 2s
to slow down or speed up the rotation period.
调整2s
以减慢或加快旋转周期。
Then add this line, outside of any selector:
然后在任何选择器之外添加以下行:
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
That’s it! Your elements should now rotate.
而已! 您的元素现在应该旋转了。
Check out the CSS Animations and CSS Transitions guides
Here is the result shown in Codepen:
这是Codepen中显示的结果:
See the Pen How to use CSS Animations to continuously rotate an image by Flavio Copes (@flaviocopes) on CodePen.
见笔如何使用CSS动画连续旋转的图像由弗拉维奥·科佩斯( @flaviocopes上) CodePen 。
翻译自: https://flaviocopes.com/rotate-image/
css连续旋转