CSS Animation: How to Achieve the Jitter Effect of Elements
CSS animation: How to achieve the jitter effect of elements
Abstract: CSS animation is a commonly used effect in web design. It can add dynamics and vividness to web pages. Feel. This article will introduce how to use CSS animation to achieve the jitter effect of elements, and attach specific code examples for reference.
- Introduction
In web design, animation effects can attract users’ attention and increase users’ interactivity and experience with web pages. Among them, CSS animation, as a simple and lightweight implementation method, is widely used in web design.
- Basic principles of CSS animation
CSS animation is achieved by changing the CSS property value of the element. In CSS, you can use the @keyframes
keyword to define key frames, and then use the animation
attribute to specify the duration, speed, number of repetitions and other attributes of the animation.
- The basic idea of implementing the jitter effect of elements
The jitter effect of elements is actually simulated by letting the element change its position quickly. The specific implementation steps are as follows:
(1) Define the key frames of the jitter animation
Use the @keyframes
keyword to define the key frames of the jitter animation. Key frames include a start state and an end state. By specifying the position of the element in the key frame, the element can achieve a jitter effect within a specified time period.
The sample code is as follows:
@keyframes shake { 0% { transform: translate(0, 0); } 10% { transform: translate(-10px, 0); } 20% { transform: translate(10px, 0); } 30% { transform: translate(-10px, 0); } 40% { transform: translate(10px, 0); } 50% { transform: translate(-10px, 0); } 60% { transform: translate(10px, 0); } 70% { transform: translate(-10px, 0); } 80% { transform: translate(10px, 0); } 90% { transform: translate(-10px, 0); } 100% { transform: translate(0, 0); } }
(2) Add animation attributes to elements
Use animation
attributes to add animation attributes to elements and specify the animation Properties such as name, duration, number of repetitions, etc.
The sample code is as follows:
.element { animation: shake 1s infinite; }
- Complete sample code
<!DOCTYPE html> <html> <head> <style> @keyframes shake { 0% { transform: translate(0, 0); } 10% { transform: translate(-10px, 0); } 20% { transform: translate(10px, 0); } 30% { transform: translate(-10px, 0); } 40% { transform: translate(10px, 0); } 50% { transform: translate(-10px, 0); } 60% { transform: translate(10px, 0); } 70% { transform: translate(-10px, 0); } 80% { transform: translate(10px, 0); } 90% { transform: translate(-10px, 0); } 100% { transform: translate(0, 0); } } .element { animation: shake 1s infinite; } </style> </head> <body> <div class="element">抖动效果</div> </body> </html>
- Summary
CSS animation is A simple, lightweight way to achieve animation effects. By using the @keyframes
keyword and animation
attributes, various animation effects can be achieved. This article introduces how to use CSS animation to achieve the jitter effect of elements, and provides specific code examples for reference. I hope this article can help readers better understand and apply the relevant knowledge of CSS animation.
The above is the detailed content of CSS Animation: How to Achieve the Jitter Effect of Elements. For more information, please follow other related articles on the PHP Chinese website!

GooFonts is a side project signed by a developer-wife and a designer-husband, both of them big fans of typography. We’ve been tagging Google

Pavithra Kodmad asked people for recommendations on what they thought were some of the most timeless articles about web development that have changed their

Learning how to build GraphQL APIs can be quite challenging. But you can learn how to use GraphQL APIs in 10 minutes! And it so happens I've got the perfect

When a component lives in an environment where the data queries populating it live nearby, there is a pretty direct line between the visual component and the

Here's some legit CSS trickery from yuanchuan. There is this CSS property offset-path. Once upon a time, it was called motion-path and then it was renamed. I

Miriam Suzanne explains in a Mozilla Developer video on the subject.


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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),

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.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools