Table of Contents
What to use to achieve css3 animation effect
Home Web Front-end Front-end Q&A What to use to achieve css3 animation effect

What to use to achieve css3 animation effect

Jun 07, 2022 pm 04:51 PM
css3

Achieve CSS3 animation effects: 1. Use the "@keyframes" rule with the animation attribute to achieve animation effects; 2. Use the transition attribute to achieve animation effects. The syntax is "element {transition: attribute name time speed curve delay} ".

What to use to achieve css3 animation effect

The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.

What to use to achieve css3 animation effect

1. What is

CSS animation (CSS Animations) is recommended for cascading style sheets to allow scalability Markup language (XML) elements use CSS animation modules

refers to the process of elements gradually transitioning from one style to another

There are many common animation effects, such as translation, Rotation, scaling, etc., complex animation is a combination of multiple simple animations

CSS ways to implement animation include the following:

transition to implement gradient animation

animation Implement custom animation

2. Implementation method

transition Implement gradient animation

The properties of transition are as follows:

  • property: fill in the css properties that need to be changed

  • duration: the time unit (s or ms) required to complete the transition effect

  • timing-function: the speed curve of the completed effect

  • delay: the delay trigger time of the animation effect

where timing-function The values ​​are as follows:

Value Description

  • linear Uniform speed (equal to cubic-bezier(0,0,1,1))

  • ease from slow to fast to slow again (cubic-bezier(0.25,0.1,0.25,1))

  • ease-in slowly becomes faster (equal to cubic-bezier (0.42,0,1,1))

  • ##ease-out slowly slows down (equal to cubic-bezier(0,0,0.58,1))

  • ease-in-out first becomes faster and then slower (equal to cubic-bezier(0.42,0,0.58,1)), fade-in effect

  • cubic-bezier(n,n,n,n) Define your own values ​​in the cubic-bezier function. Possible values ​​are numeric values ​​between 0 and 1

Note: Not all attributes can use transitions, such as display:nonedisplay:block

For example, realize the animation effect of changing when the mouse moves up

<!DOCTYPE html>
<html>
<head>
<style> 
div
{
width:100px;
height:100px;
background:blue;
transition:width 2s;
-moz-transition:width 2s; /* Firefox 4 */
-webkit-transition:width 2s; /* Safari and Chrome */
-o-transition:width 2s; /* Opera */
}
div:hover
{
width:300px;
}
</style>
</head>
<body>
<div></div>
<p>请把鼠标指针移动到蓝色的 div 元素上,就可以看到过渡效果。</p>
<p><b>注释:</b>本例在 Internet Explorer 中无效。</p>
</body>
</html>
Copy after login

Output result:

What to use to achieve css3 animation effect

animation to realize custom animation

animation is the abbreviation of 8 attributes, which are as follows:

  • animation-duration specifies the time required for the animation to complete a cycle, in seconds (s) or milliseconds (ms), the default is 0

  • animation-timing-function specifies the animation timing function, that is, the speed curve of the animation, the default is "ease" linear, ease, ease-in, ease- out, ease-in-out

  • animation-delay specifies the animation delay time, that is, when the animation starts, the default is 0

  • animation- iteration-count specifies the number of animation playback times, the default is 1

  • animation-direction specifies the direction of animation playback, the default is normal normal, reverse, alternate, alternate-reverse

  • animation-fill-mode Specifies animation fill mode. The default is none forwards, backwards, both

  • animation-play-state specifies the animation playback state, running or paused. The default is running running, pauser

  • animation-name specifies the name of @keyframes animation

CSS animation only needs to define some key frames, and For the remaining frames, the browser will interpolate and calculate based on the timing function,

define key frames through @keyframes

Therefore, if we want to rotate the element in a circle , you only need to define the start and end frames:

@keyframes rotate{
    from{
        transform: rotate(0deg);
    }
    to{
        transform: rotate(360deg);
    }
}
Copy after login

from represents the first frame, to represents the frame at the end

You can also use percentages to describe the life cycle

@keyframes rotate{
    0%{
        transform: rotate(0deg);
    }
    50%{
        transform: rotate(180deg);
    }
    100%{
        transform: rotate(360deg);
    }
}
Copy after login

After defining the keyframe, you can use it directly:

animation: rotate 2s;
Copy after login

3. Summary

transition (transition) is used to set The overstyle of elements has a similar effect to animation, but the details are very different.

transform (transform) is used to rotate, scale, move or tilt elements, and has nothing to do with the animation of setting styles. Relationship, just like color, is used to set the "appearance" of an element.

translate (movement) is just an attribute value of transform, that is, movement.

animation (animation) is used to set animation properties. It is an abbreviated attribute, including 6 attributes

(Learning video sharing:

css video tutorial)

The above is the detailed content of What to use to achieve css3 animation effect. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1249
24
How to achieve wave effect with pure CSS3? (code example) How to achieve wave effect with pure CSS3? (code example) Jun 28, 2022 pm 01:39 PM

How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

Use CSS skillfully to realize various strange-shaped buttons (with code) Use CSS skillfully to realize various strange-shaped buttons (with code) Jul 19, 2022 am 11:28 AM

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

How to hide elements in css without taking up space How to hide elements in css without taking up space Jun 01, 2022 pm 07:15 PM

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

It turns out that text carousel and image carousel can also be realized using pure CSS! It turns out that text carousel and image carousel can also be realized using pure CSS! Jun 10, 2022 pm 01:00 PM

How to create text carousel and image carousel? The first thing everyone thinks of is whether to use js. In fact, text carousel and image carousel can also be realized using pure CSS. Let’s take a look at the implementation method. I hope it will be helpful to everyone!

How to enlarge the image by clicking the mouse in css3 How to enlarge the image by clicking the mouse in css3 Apr 25, 2022 pm 04:52 PM

Implementation method: 1. Use the ":active" selector to select the state of the mouse click on the picture; 2. Use the transform attribute and scale() function to achieve the picture magnification effect, the syntax "img:active {transform: scale(x-axis magnification, y Axis magnification);}".

How to set animation rotation speed in css3 How to set animation rotation speed in css3 Apr 28, 2022 pm 04:32 PM

In CSS3, you can use the "animation-timing-function" attribute to set the animation rotation speed. This attribute is used to specify how the animation will complete a cycle and set the speed curve of the animation. The syntax is "element {animation-timing-function: speed attribute value;}".

Does css3 animation effect have deformation? Does css3 animation effect have deformation? Apr 28, 2022 pm 02:20 PM

The animation effect in css3 has deformation; you can use "animation: animation attribute @keyframes ..{..{transform: transformation attribute}}" to achieve deformation animation effect. The animation attribute is used to set the animation style, and the transform attribute is used to set the deformation style. .

See all articles