CSS3 realizes the red envelope shaking effect

CSS3 realizes the red envelope shaking effect

There is a requirement to realize the shaking effect of red envelopes. I have never done it before. I will record it. Hehe~~
The transform: rotate() property is used here, and animation is added to achieve the animation effect. I won’t go into the code.

.red_packet {
  width: 180rpx;
  height: 220rpx;
  position: fixed;
  top: 10rpx;
  right: 20rpx;
  color: #D60E19;
  animation: shake .5s linear infinite;
}
@keyframes shake {

  25% {
    transform: rotate(7deg);
  }
  75% {
    transform: rotate(-7deg);
  }

  50%,
  100% {
    transform: rotate(0);
  }
}

The effect that was initially achieved was like this

It keeps swinging left and right, but the desired effect is to shake twice every few seconds. What should I do if animation does not support interval animation? After searching on Baidu, I found that by setting the percentage, the first three seconds will not move, and the shaking will start from 70%, and it must be fast, accurate and ruthless. After some improvement, the effect is as follows:

.red_packet {
  width: 180rpx;
  height: 220rpx;
  position: fixed;
  top: 10rpx;
  right: 20rpx;
  color: #D60E19;
  animation: shake 3s linear infinite;
}

@keyframes shake {

  70%, 80% {
    transform: rotate(7deg);
  }
  75% {
    transform: rotate(-7deg);
  }

  65%,
  85% {
    transform: rotate(0);
  }
}

This is the end of this article about how to achieve red envelope shaking effect with CSS3. For more relevant CSS3 red envelope shaking content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  The process of installing Docker in Linux system

>>:  Detailed explanation of CSS style sheets and format layout

Recommend

Docker data management and network communication usage

You can install Docker and perform simple operati...

Troubleshooting and solutions for MySQL auto-increment ID oversize problem

introduction Xiao A was writing code, and DBA Xia...

Native js to achieve seamless carousel effect

Native js realizes the carousel effect (seamless ...

About React Native unable to link to the simulator

React Native can develop iOS and Android native a...

A complete list of common Linux system commands for beginners

Learning Linux commands is the biggest obstacle f...

MySQL 5.7.21 installation and configuration tutorial under Window10

This article records the installation and configu...

The latest Linux installation process of tomcat8

Download https://tomcat.apache.org/download-80.cg...

A screenshot demo based on canvas in html

Written at the beginning I remember seeing a shar...

What is ssh? How to use? What are the misunderstandings?

Table of contents Preface What is ssh What is ssh...

How to implement the builder pattern in Javascript

Overview The builder pattern is a relatively simp...

Teach you how to get the pointer position in javascript

The method of obtaining the position of the point...

Detailed explanation of Linux kernel macro Container_Of

Table of contents 1. How are structures stored in...

Vue encapsulates the public function method of exporting Excel data

vue+element UI encapsulates a public function to ...