The hover button is enlarged to achieve interactive effects through transform: scale() and transition; 2. Fade in animation using @keyframes fadeIn with animation: forwards to maintain the final state; 3. Infinite rotation icon uses transform: rotate() and border differences to create loading effects; 4. Left and left jitter prompts move between 25% and 75% keyframes through translateX to generate warning feedback; 5. Slide up and down banners from negative values to 0 to slide into vision; 6. Text typewriter effect simulates verbatim input through width gradient and steps() and adds cursor flashing; 7. Pulse aperture uses scale and opacity to achieve breathing highlighting prompts; all animations should focus on performance optimization to avoid excessive use interfering with user experience, and the final effect should be natural and smooth and serve functions.
CSS animation is an important means to improve user experience in web design. Through @keyframes
and animation
attributes, we can achieve various smooth and natural visual effects. Below are some practical and common CSS animation examples for reference by beginners and advanced developers.

1. Scale Animation
Commonly used for buttons or icons, slightly enlargement when hovering, increasing the sense of interaction.
.btn { padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; transition: transform 0.3s ease; } .btn:hover { transform: scale(1.1); }
Use
transform: scale()
andtransition
to achieve smooth zooming, which is more efficient than directly changingwidth/height
.
2. Fade In
A gradual effect from transparent to opaque when a page is loaded or an element appears.
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } .fade-in { animation: fadeIn 1s ease-in forwards; }
forwards
means that the animation is maintained at the last frame state after the end to prevent flashbacks.
3. Spin Animation
Suitable for loading icons or rotating logos.
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .spinner { width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; animation: spin 1s linear infinite; }
This is a classic "loading circle" effect that uses the color difference of the border to create a sense of rotation.
4. Shake Animation prompt
Used for form error prompts or button click feedback.
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } } .shake { animation: shake 0.5s ease-in-out; }
Suitable for short and eye-catching feedback animations, do not overuse them to avoid disturbing users.
5. Slide In from Top
Commonly found in the notification bar or the top prompt bar.
@keyframes slideInTop { from { transform: translateY(-100%); } to { transform: translateY(0); } } .banner { background: #ff6b6b; color: white; padding: 15px; text-align: center; animation: slideInTop 0.6s ease-out; }
The animation slides in from the top of the screen, and the automatic hiding effect is better with timing.
6. Typewriter Effect
Simulates the animation of text input verbatim.
.typewriter { overflow: hidden; border-right: 2px solid black; white-space: nowrap; margin: 0 auto; letter-spacing: 0.1em; animation: typing 3.5s steps(30, end) forwards, blink-caret 0.75s step-end infinite; } @keyframes typing { from { width: 0 } to { width: 100% } } @keyframes blink-caret { from, to { border-color: transparent } 50% { border-color: black } }
Note: This effect requires that the element is
block
orinline-block
and set fixed width or parent container limits.
7. Pulse Animation
Commonly used for focus prompts or new feature guidance.
@keyframes pulse { 0% { transform: scale(0.95); opacity: 1; } 70% { transform: scale(1.05); opacity: 0.5; } 100% { transform: scale(0.95); opacity: 1; } } .pulse { animation: pulse 1.5s infinite ease-in-out; }
Can be used to highlight the Click here or New Message icon.
A brief description of commonly used animation properties:
property | illustrate |
---|---|
animation-name
|
Specify the @keyframes name |
animation-duration
|
Animation duration (such as 1s) |
animation-timing-function
|
Ease, linear, ease-in-out |
animation-delay
|
Delay start time |
animation-iteration-count
|
Number of times (infinite means infinite) |
animation-direction
|
Direction (normal, reverse, alternate) |
animation-fill-mode
|
Outside the animation state (forwards, backwards) |
animation-play-state
|
Control playback/pause (running, paused) |
Basically, these common and practical animation examples. You can copy these codes into the project and use them directly, and then fine-tune the time, color, or size according to the design. The key is to keep the animation natural and not interfere with user operations .
Small suggestions: Consider using
will-change
ortransform
for complex animations to improve performance, avoid frequent re-arrangement and redrawing.
The above is the detailed content of css animation examples. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Introduction to Python functions: Usage and examples of the isinstance function Python is a powerful programming language that provides many built-in functions to make programming more convenient and efficient. One of the very useful built-in functions is the isinstance() function. This article will introduce the usage and examples of the isinstance function and provide specific code examples. The isinstance() function is used to determine whether an object is an instance of a specified class or type. The syntax of this function is as follows

The DECODE function in Oracle is a conditional expression that is often used to return different results based on different conditions in query statements. This article will introduce the syntax, usage and sample code of the DECODE function in detail. 1. DECODE function syntax DECODE(expr,search1,result1[,search2,result2,...,default]) expr: the expression or field to be compared. search1,

Indentation specifications and examples of Go language Go language is a programming language developed by Google. It is known for its concise and clear syntax, in which indentation specifications play a crucial role in the readability and beauty of the code. effect. This article will introduce the indentation specifications of the Go language and explain in detail through specific code examples. Indentation specifications In the Go language, tabs are used for indentation instead of spaces. Each level of indentation is one tab, usually set to a width of 4 spaces. Such specifications unify the coding style and enable teams to work together to compile

Introduction to Python functions: functions and examples of the eval function In Python programming, the eval function is a very useful function. The eval function can execute a string as program code, and its function is very powerful. In this article, we will introduce the detailed functions of the eval function, as well as some usage examples. 1. Function of eval function The function of eval function is very simple. It can execute a string as Python code. This means that we can convert a string

Introduction to Python functions: The role and examples of the filter function Python is a powerful programming language that provides many built-in functions, one of which is the filter function. The filter function is used to filter the elements in the list and return a new list composed of elements that meet the specified conditions. In this article, we will introduce what the filter function does and provide some examples to help readers understand its usage and potential. The syntax of the filter function is as follows: filter(function

Application and example analysis of PHP dot operator In PHP, the dot operator (".") is an operator used to connect two strings. It is very commonly used and very flexible when concatenating strings. By using the dot operator, we can easily concatenate multiple strings to form a new string. The following will introduce the use of PHP dot operators through example analysis. 1. Basic usage First, let’s look at a basic usage example. Suppose there are two variables $str1 and $str2, which store two words respectively.

Introduction to Python functions: Introduction and examples of range functions Python is a high-level programming language widely used in various fields. It is easy to learn and has a rich built-in function library. Among them, the range function is one of the commonly used built-in functions in Python. This article will introduce the function and usage of the range function in detail, and demonstrate its specific application through examples. The range function is a function used to generate an integer sequence. It accepts three parameters, which are the starting value (

Introduction to Python functions: Usage and examples of getattr function In Python, getattr() is a built-in function used to obtain the attribute value of an object. Without knowing the object's attribute name, you can use the getattr() function to dynamically access the attribute. This article will introduce the syntax, usage and examples of the getattr() function. The syntax of the getattr() function is as follows: getattr(object,name[,default]) parameters
