freeCodeCamp 响应式网页设计的认证课程第十五章。你可以使用 CSS 动画将注意力吸引到网页的特定部分并使其更具吸引力。在通过构建摩天轮学习 CSS 动画的课程中,建造一个摩天轮,学习如何使用 CSS 为元素设置动画、转换它们并调整它们的速度。以下为我在学习和实战练习过程中所做的笔记,可供参考。
一、重点 CSS 代码
Draw a wheel:
1 | .wheel { |
The transform-origin
property is used to set the point around which a CSS transformation is applied:
1 | .line { |
The transform
property allows you to manipulate the shape of an element:
1 | .line:nth-of-type(2) { |
Set the origin point to be offset 50%
from the left and 0%
from the top, placing it in the middle of the top edge of the element:
1 | .cabin { |
The @keyframes
at-rule is used to define the flow of a CSS animation. Within the @keyframes
rule, you can create selectors for specific points in the animation sequence, such as 0%
or 25%
, or use from
and to
to define the start and end of the sequence;
@keyframes
rules require a name to be assigned to them, which you use in other rules to reference. For example, the @keyframes freeCodeCamp { }
rule would be named freeCodeCamp
:
1 | @keyframes wheel { |
The animation-name
property is used to link a @keyframes
rule to a CSS selector;
The animation-duration
property is used to set how long the animation should sequence to complete;
The animation-iteration-count
property sets how many times your animation should repeat;
The animation-timing-function
property sets how the animation should progress over time:
1 | .wheel { |
Use the animation
property to set these all at once:
1 | .cabin { |
@keyframes
cabins:
1 | @keyframes cabins { |