8.13. CSS3 animation

发布时间 :2024-01-16 23:00:05 UTC      

8.13.1. CSS3 animation

CSS3 can create animations, which can replace many web animated images, Flash animations, and JavaScript effects.

CSS3 animation

8.13.2. CSS3 @keyframes rules

To create a CSS3 animation, you need to understand @keyframes rules.

The @keyframes rule is to create an animation.

@keyframes specifying a CSS style and animation within the rule will gradually change from the current style to the new style.

8.13.3. Browser support

The number in the table represents the first browser version number that supports the property.

The number immediately preceding -webkit- , -ms- , or -moz- is the first browser version number that supports the prefix attribute.

Attribute

@ keyframes

43.0 4.0-webkit-

10.0

16.05.0-moz-

9.04.0-webkit-

30.0 15.0-webkit- 12.0-o-

Animation

43.0 4.0-webkit-

10.0

16.05.0-moz-

9.04.0-webkit-

30.0 15.0-webkit- 12.0-o-

Example

@keyframes myfirst
{
    from {background: red;}
    to {background: yellow;}
}

@-webkit-keyframes myfirst /* Safari and Chrome */
{
    from {background: red;}
    to {background: yellow;}
}

8.13.4. CSS3 animation

When in @keyframes create an animation and bind it to a selector, otherwise the animation will have no effect.

Specify that the animation properties of at least two CSS3 are bound to one selector:

  • Specify the name of the animation

  • Specify the duration of the animation

Example

Bind the “myfirst” animation to div element, duration: 5 seconds:

div
{
    animation: myfirst 5s;
    -webkit-animation: myfirst 5s; /* Safari and Chrome */
}

Note: you must define the name and duration of the animation. If you omit the duration, the animation will not run because the default value is 0.

8.13.5. What is CSS3 animation?

Animation is the effect of gradually changing elements from one style to another.

You can change as many styles as you want and as many times as you like.

Please specify when the change occurs as a percentage, or use the keywords “from” and “to”, which are equivalent to 0% and 100%.

0% is the beginning of the animation and 100% is the completion of the animation.

For optimal browser support, you should always define 0% and 100% selectors.

Example

Change the background color when the animation is 25% and 50%, and then change it again when the animation is 100% complete:

@keyframes myfirst
{
    0%   {background: red;}
    25%  {background: yellow;}
    50%  {background: blue;}
    100% {background: green;}
}

@-webkit-keyframes myfirst /* Safari and Chrome */
{
    0%   {background: red;}
    25%  {background: yellow;}
    50%  {background: blue;}
    100% {background: green;}
}

Example

Change the background color and position:

@keyframes myfirst
{
    0%   {background: red; left:0px; top:0px;}
    25%  {background: yellow; left:200px; top:0px;}
    50%  {background: blue; left:200px; top:200px;}
    75%  {background: green; left:0px; top:200px;}
    100% {background: red; left:0px; top:0px;}
}

@-webkit-keyframes myfirst /* Safari and Chrome */
{
    0%   {background: red; left:0px; top:0px;}
    25%  {background: yellow; left:200px; top:0px;}
    50%  {background: blue; left:200px; top:200px;}
    75%  {background: green; left:0px; top:200px;}
    100% {background: red; left:0px; top:0px;}
}

8.13.6. Animation properties of CSS3

The following table lists @keyframes rules and all animation attributes:

Attribute

Description

CSS

@keyframes

Prescribe animation.

3

animation

The abbreviated attribute of all animation attributes.

3

animation-name

Specifies the name of the @ keyframes animation.

3

animation-duration

Specifies the seconds or milliseconds it takes for the animation to completea cycle. The default is 0.

3

animation-timing-function

Specifies the speed curve of the animation. Default is “ease”.

3

animation-fill-mode

Specifies the style to be applied to the element when the animation is not played (when the animation is complete, or when the animation has a delay that does not start playing).

3

animation-delay

Specify when the animation starts. The default is 0.

3

animation-iteration-count

Specifies the number of times the animation is played. The default is 1.

3

animation-direction

Specifies whether the animation is played in reverse in the next cycle. Default is “normal”.

3

animation-play-state

Specifies whether the animation is running or paused. Default is “running”.

3

The following two examples set all animation properties:

Example

Running myfirst animate, set all the attributes:

div
{
    animation-name: myfirst;
    animation-duration: 5s;
    animation-timing-function: linear;
    animation-delay: 2s;
    animation-iteration-count: infinite;
    animation-direction: alternate;
    animation-play-state: running;
    /* Safari and Chrome: */
    -webkit-animation-name: myfirst;
    -webkit-animation-duration: 5s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-delay: 2s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-direction: alternate;
    -webkit-animation-play-state: running;
}

Example

Same as the above animation, but using an abbreviated animation animation attributes:

div
{
    animation: myfirst 5s linear 2s infinite alternate;
    /* Safari and Chrome: */
    -webkit-animation: myfirst 5s linear 2s infinite alternate;
}

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.