search
HomeWeb Front-endCSS TutorialCSS Animation: How to Achieve the Jitter Effect of Elements

CSS Animation: How to Achieve the Jitter Effect of Elements

Nov 21, 2023 am 09:36 AM
elementcss animationjitter effect

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.

  1. 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.

  1. 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.

  1. 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;
}
  1. 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>
  1. 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!

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
How We Tagged Google Fonts and Created goofonts.comHow We Tagged Google Fonts and Created goofonts.comApr 12, 2025 pm 12:02 PM

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

Timeless Web Dev ArticlesTimeless Web Dev ArticlesApr 12, 2025 am 11:44 AM

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

The Deal with the Section ElementThe Deal with the Section ElementApr 12, 2025 am 11:39 AM

Two articles published the exact same day:

Practice GraphQL Queries With the State of JavaScript APIPractice GraphQL Queries With the State of JavaScript APIApr 12, 2025 am 11:33 AM

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

Component-Level CMSsComponent-Level CMSsApr 12, 2025 am 11:09 AM

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

Set Type on a Circle... with offset-pathSet Type on a Circle... with offset-pathApr 12, 2025 am 11:00 AM

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

What does 'revert' do in CSS?What does 'revert' do in CSS?Apr 12, 2025 am 10:59 AM

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

The Modern LoversThe Modern LoversApr 12, 2025 am 10:58 AM

I love stuff like this.

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

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

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools