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

Three ways to check whether a port is open in a remote Linux system

This is a very important topic, not only for Linu...

Detailed explanation of HTML form elements (Part 1)

HTML forms are used to collect different types of...

Docker builds Redis5.0 and mounts data

Table of contents 1. Simple mounting of persisten...

Specific use of the wx.getUserProfile interface in the applet

Recently, WeChat Mini Program has proposed adjust...

CSS3 realizes draggable Rubik's Cube 3D effect

Mainly used knowledge points: •css3 3d transforma...

React event mechanism source code analysis

Table of contents Principle Source code analysis ...

js simple and crude publish and subscribe sample code

What is Publish/Subscribe? Let me give you an exa...

VUE realizes registration and login effects

This article example shares the specific code of ...

Detailed tutorial for installing ElasticSearch:7.8.0 cluster with docker

ElasticSearch cluster supports動態請求的方式and靜態配置文件to ...

Detailed explanation of MySQL Explain

In daily work, we sometimes run slow queries to r...

Detailed explanation of MySQL redo log (redo log) and rollback log (undo logo)

Preface: The previous article described several c...

Develop a vue component that encapsulates iframe

Table of contents 1. Component Introduction 2. Co...