search
HomeWeb Front-endCSS TutorialUse CSS3 transformation, transition, animation, and related attribute analysis

1. Transformation

Transform: You can rotate rotate, scale, move translate, tilt skew, and matrix deform matrix on element objects.
Example:

<strong>transform: rotate(90deg) scale(1.5,0.8) translate(100px,50px) skew(45deg,45deg);<br>/*矩阵变形*/<br>matrix(<number>,<number>,<number>,<number>,<number>,<number>);<br>/*透视*/<br>perspective(length);</number></number></number></number></number></number></strong>

transition: transition attribute

transition: css attribute name of transition effect duration of transition speed speed curve of effect Over effect start time;

<strong>transition: property duration timing-function delay;<br>/*示例*/<br>transition:1s ease all;<br>-webkit-tansition:1s ease all;<br>-moz-transition:1s ease all;<br>-o-transition:1s ease all;</strong>

rotate(): Rotate element in two-dimensional space.

If the element has a perspective value set, rotate3d() can be used to achieve rotation in three-dimensional space.

<strong>rotateX(angele)/*相当于rotate3d(1,0,0,angle)指定在三维空间内的X轴旋转*/<br>rotateY(angele)/*相当于rotate3d(0,1,0,angle)指定在三维空间内的Y轴旋转*/<br>rotateZ(angele)/*相当于rotate3d(0,0,1,angle)指定在三维空间内的Z轴旋转*/</strong>

scale()

<strong>scaleX(<number>)/*只在X轴(水平方向)缩放元素*/<br>scaleY(<number>)/*只在Y轴(垂直方向)缩放*/<br>scaleZ(<number>)/*只在Z轴缩放,前提:元素设定透视值*/</number></number></number></strong>

translate([,]): Movement is the displacement amount.

<strong>translateX(<translation-value>);/*只在X轴(水平方向)移动*/<br>translateY(<translation-value>);/*只在Y轴(垂直方向)移动*/<br>translateZ(<translation-value>);/*只在Z轴移动,前提:元素设置透视值*/</translation-value></translation-value></translation-value></strong>

skew(): skew

<strong>skewX(<angle>);/*只在X轴(水平)倾斜*/<br>skewY(<angle>);/*只在Y轴(垂直)倾斜*/</angle></angle></strong>

matrix(a,c,e,b,d,f): matrix deformation, c , the value of e is represented by sine or cosine value.

a: represents scaleX(); X-axis scaling
c: skewY(); Y-axis tilt
e: skewX(); X-axis tilt
b :scaleY(); Y-axis scaling
d:translateX() X-axis movement
f:translateY() Y-axis movement

transform:matrix(<number>,<number>,<number>,<number>,<number>,<number>);</number></number></number></number></number></number>

perspective():Perspective

<strong>.wrap{<br>    perspective:1000px; 
<br>}<br>.wrap .child{<br>    transform:perspective(1000px);<br>}</strong>

2. Transition

transition-property: transition property

<strong>transition-property:all;/*针对所有元素都有过度效果*/<br>transition-property:none;/*没有元素有过度效果*/<br>transition-property:ident;/*指定css属性有过度效果,例如width*/</strong>

transition-duration: Transition time
transition-delay: delay time, when it is negative, the transition action will start to be displayed from this time point, and the previous action will be truncated.
Transition-timing-function: transition effect, default ease.

<strong>transition-timing-function:ease;/*缓解效果,等同于cubic-bezier(0.25,0.1,0.25,1.0)函数,既立方贝塞尔*/<br>transition-timing-function:linear;/*线性效果,等同于cubic-bezier(0.0,0.0,1.0,1.0)函数*/<br>transition-timing-function:ease-in;/*渐显效果,等同于cubic-bezier(0.42,0,1.0,1.0)函数*/<br>transition-timing-function:ease-out;/*渐隐效果,等同于cubic-bezier(0,0,0.58,1.0)函数*/<br>transition-timing-function:ease-in-out;/*渐显渐隐效果,等同于cubic-bezier(0.42,0,0.58,1.0)函数*/<br>transition-timing-function:cubic-bezier;/*特殊的立方贝塞尔曲线效果*/</strong>

3. Animation

animation-name: animation name, must be used in conjunction with the rule @keyframes, because the animation name is defined by @keyframes , if multiple attribute values ​​are provided, separate them with commas.

@keyframes is equivalent to a namespace, followed by a noun. If the animation-name in the class defines the corresponding name, the animation can be executed. When defining animation, you can directly use the keywords from and to to transition from one state to another.

<strong>.animation_name{<br>    left:0;<br>    top:100px;<br>    position: absolute;<br>    -webkit-animation: 0.5s 0.5s ease infinite alternate;<br>    -moz-animation: 0.5s 0.5s ease infinite alternate;<br>    -webkit-animation-name:demo;<br>    -moz-animation-name:demo;<br>}<br>@-webkit-keyframes demo{<br>    from{left:0;}<br>    to{left:400px;}<br>}<br>@-webkit-keyframes demo1{<br>    0%{left:0;}<br>    50%{left:200px;}<br>    100%{left:400px;}<br>}</strong>

animation-duration: animation time

animation-timing-function: playback method, the values ​​are as follows:

ease: The mitigation effect is equivalent to the cubic-bezier(0.25,0.1,0.25,1.0) function, which is cubic Bezier.
linear:linear effect
ease-in:fading effect
ease-out:fading effect
ease-in-out:fading effect
step-start:jump immediately Go to the end state of the animation
step-end: Keep the start state of the animation. When the animation execution time is over, jump to the end state of the animation immediately
step([,[start | end]]?): The first parameter number is the specified number of intervals, that is, the animation is divided into n steps for phased display. The second parameter defaults to end, which sets the last step state. start is the state at the end, and end is the state at the beginning. If set with animation- The effect of fill-mode conflicts, and the setting of animation-fill-mode is the animation end state.
cubic-bezier(,,,): Special cubic zebel curve effect

animation-delay: Start playback time

animation-iteration-count: The number of playback times. When the value is infinite, it means infinite loop playback

animation-direction: The playback direction. The value is:

normal: normal direction
reverse: the animation runs in reverse, the direction is always similar to normal
alternate: the animation will cycle forward and reverse alternately

animation-fill- mode: The state after playback, value:

none: Default value, not set
forwards: Keep the animation ended state after the end
backwards: Return to the animation after the end State at the beginning
both: After the end, you can follow the two rules of forwards and backwards
animation-play-state: Retrieve or set the state of the object animation, value:
running: default, motion
paused : Pause

4. Associated attributes

transform-origin: Transform origin, reference point of transform, defaults to the center point of the element. There are two parameters, parameter one is the abscissa, and parameter two is the ordinate.

percentage: Use percentage to specify coordinate value, can be negative
length: Use length to specify coordinate value, can be negative
left center right: Horizontal value
top center bottom: vertical direction value

perspective-prigin: perspective origin, defined on the X-axis and Y-axis of the 3D element, allowing the bottom position of the 3D element to be changed. When defining this attribute, It is a child element of an element, the perspective, not the element itself.
Note: This attribute must be used together with the perspective attribute, which only affects 3D transformed elements.
Values: percentage, length, left, center, right, top, center, bottom

##backface-visibility: Hide the back of the content, the back is visible by default, inverted The content after the transformation is still visible. When backface-visibility is set to hidden, the content will be hidden after rotation, and the front face will no longer be visible after rotation. Values: visible, hidden
transform-style: 3D rendering, sets how embedded elements are rendered in 3D space. There are two values:
flat: all child elements are rendered in a 2D plane
preserve-3d: Preserve 3D space








The above is the detailed content of Use CSS3 transformation, transition, animation, and related attribute analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
Iterating a React Design with Styled ComponentsIterating a React Design with Styled ComponentsApr 21, 2025 am 11:29 AM

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons!Oh, the Many Ways to Make Triangular Breadcrumb Ribbons!Apr 21, 2025 am 11:26 AM

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG Properties in CSS GuideSVG Properties in CSS GuideApr 21, 2025 am 11:21 AM

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

A Few Functional Uses for Intersection Observer to Know When an Element is in ViewA Few Functional Uses for Intersection Observer to Know When an Element is in ViewApr 21, 2025 am 11:19 AM

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

Revisting prefers-reduced-motionRevisting prefers-reduced-motionApr 21, 2025 am 11:18 AM

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

How to Get a Progressive Web App into the Google Play StoreHow to Get a Progressive Web App into the Google Play StoreApr 21, 2025 am 11:10 AM

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

The Simplest Ways to Handle HTML IncludesThe Simplest Ways to Handle HTML IncludesApr 21, 2025 am 11:09 AM

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

Change Color of SVG on HoverChange Color of SVG on HoverApr 21, 2025 am 11:04 AM

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,

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

Video Face Swap

Video Face Swap

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

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

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.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.