search
HomeWeb Front-endCSS TutorialIntroduction to transition and animation properties of css3 animation

Introduction to transition and animation properties of css3 animation

Oct 11, 2018 pm 04:07 PM
animationcss3css3 animationtransition

This article will introduce to you the transition and animation attributes for realizing CSS3 animation. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

tradition has a total of 4 properties:

  • ##transition-property transition property

  • Transition-duration The time required to complete the animation, calculated in seconds or milliseconds

  • transition-timing-function specifies the animation change speed curve

  • transition-delay Whether to delay

transition-property Transition property

none: No properties will be obtained Transition effect

all: All attributes will obtain the transition effect

porperty: width, height...

img{    
    height:15px;    
    width:15px;
}
img:hover{    
    height: 450px;    
    width: 450px;
}
The function of transition is to specify the time required for state changes.

img{
    transition: 1s;
}

transition-duration seconds or milliseconds to complete the state transition

You can also specify the change attribute of the transition, such as width change or height

img{
    transition: 1s height;
}
Multiple attributes can also be specified

img{
    transition: 1s height, 1s width
}

transition-delay state change speed.

Specify the delay parameter so that the height changes first, and then the width changes:

img{
    transition: 1s height, 1s 1s width
}
The real meaning of delay is to specify the order in which the animation occurs, so that multiple different Transition can occur at different moments to form an animation effect

transition-timing-function state change speed

The default is to gradually slow down ease

Possible values ​​are

  • linear: uniform speed

  • easy-in: acceleration

  • ease -out: deceleration

  • cubic-bezier function, custom speed mode

(cubic: cubic, bezier:

Bezier Er curve)

cubic-bezier (, , , ) value range 0-1

img{    
    transition-property: height;         
    transition-duration: 1s;    
    transition-delay: 1s;    
    transition-timing-function: ease;
}
Note :Transition requires clear knowledge of the specific values ​​of the start state and end state in order to calculate the intermediate state. But the transition cannot calculate the state of 0->auto, so there will be no animation effect. Similar situations include display: none->block and background:url(foo.jpg)->url(bar.jpg).

It has some disadvantages:

  1. Requires event triggering, which cannot occur directly when the web page is loaded

  2. It is a one-time event Yes, it cannot happen repeatedly unless you trigger it repeatedly

  3. Only the start state and the end state can be defined, and the intermediate state cannot be defined

  4. A transition Rules can only define changes to one attribute

animation

CSS Animation has the following attributes:

  • animation-name The name that needs to be bound to the selector keyframe

  • animation-duration The time required to complete the animation, calculated in seconds or milliseconds

  • animation-timing-function specifies the speed curve of the animation

  • animaton-delay The delay time before the animation starts

  • animation-iteration-count The number of times the animation should be played

  • animation-direction Whether the animation should be played in reverse in turn

  • animation-fill -mode attribute specifies whether the dynamic effect is visible after the animation is played

  • animatoin-play-state specifies whether the animation is running or paused

iteration-repeat

animation-name

animation-duration

首先 设置动画的名称和持续的时长

p:hover{
animation: 1s rainbow;
}

上面代码表示,当鼠标悬停在p元素上时,会产生名为rainbow的动画效果,持续时间为1秒。为此,我们还需要用keyframes关键字,定义rainbow效果。

@keyframs rainbow{
0% { background: #c00; }
50% { background: orange; }
100% { background: yellowgreen; }
}

keyframs的写法相当自由

可以用from表示0%,to 表示100%

@keyframs rainbow{
from { background: #c00; }
50% { background: orange; }
to { background: yellowgreen; }
}

如果忽略某个状态,浏览器会自动推算

@keyframs rainbow{
   50% { background: orange; }
     to { background: yellowgreen; }
}

@keyframs rainbow{
to { background: yellowgreen; }
}

@keyframs rainbow{
from, to { background: yellowgreen; }
}

浏览器从一个状态到另外一个状态是平滑过渡到,steps函数实现分步过渡

p:hover {
animation: 1s rainbow infinite steps(10);
}

默认情况下,动画只播放一次。加入infinite关键字,可以让动画无限次播放。

p:hover{
animation: 1s rainbow infinite;
}

除了infinite,还可以设置为具体的次数: 3、5

p:hover{
animation: 1s rainbow 5;
}

animation-fill-mode

动画结束以后会立即冲结束状态回到起始状态,如果想让动画保持在结束状态就要加上animation-fill-mode属性中的forwards

p:hover{
animation: 1s rainbow infinite forwards;
}

animation-fill-mode 有4种取值

none  不改变默认行为

forawads  动画完成后,保持最后一个属性(在最后一个关键帧中定义)

backwards  在 animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值(在第一个关键帧中定义)。

both  向前向后都进行填充

animation-direction

规定了轮流反向播放动画

alternate:动画会在奇数次(1,3,5...)正常播放,偶数次(2,4,6...)反向播放

最常用alternate和revers,浏览器对其他值的支持不佳

<iframe 
width="100%" height="300" src="//jsfiddle.net/xiaoying/2414dr39/embedded/">
</iframe>

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。更多相关教程请访问 CSS3视频教程

相关推荐:

php公益培训视频教程

CSS在线手册

CSS3在线手册

div/css图文教程

css3特效代码大全

The above is the detailed content of Introduction to transition and animation properties of css3 animation. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
How much specificity do @rules have, like @keyframes and @media?How much specificity do @rules have, like @keyframes and @media?Apr 18, 2025 am 11:34 AM

I got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?

Can you nest @media and @support queries?Can you nest @media and @support queries?Apr 18, 2025 am 11:32 AM

Yes, you can, and it doesn't really matter in what order. A CSS preprocessor is not required. It works in regular CSS.

Quick Gulp Cache BustingQuick Gulp Cache BustingApr 18, 2025 am 11:23 AM

You should for sure be setting far-out cache headers on your assets like CSS and JavaScript (and images and fonts and whatever else). That tells the browser

In Search of a Stack That Monitors the Quality and Complexity of CSSIn Search of a Stack That Monitors the Quality and Complexity of CSSApr 18, 2025 am 11:22 AM

Many developers write about how to maintain a CSS codebase, yet not a lot of them write about how they measure the quality of that codebase. Sure, we have

Datalist is for suggesting values without enforcing valuesDatalist is for suggesting values without enforcing valuesApr 18, 2025 am 11:08 AM

Have you ever had a form that needed to accept a short, arbitrary bit of text? Like a name or whatever. That's exactly what is for. There are lots of

Front Conference in ZürichFront Conference in ZürichApr 18, 2025 am 11:03 AM

I'm so excited to be heading to Zürich, Switzerland for Front Conference (Love that name and URL!). I've never been to Switzerland before, so I'm excited

Building a Full-Stack Serverless Application with Cloudflare WorkersBuilding a Full-Stack Serverless Application with Cloudflare WorkersApr 18, 2025 am 10:58 AM

One of my favorite developments in software development has been the advent of serverless. As a developer who has a tendency to get bogged down in the details

Creating Dynamic Routes in a Nuxt ApplicationCreating Dynamic Routes in a Nuxt ApplicationApr 18, 2025 am 10:53 AM

In this post, we’ll be using an ecommerce store demo I built and deployed to Netlify to show how we can make dynamic routes for incoming data. It’s a fairly

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.