How to stop CSS animation midway and maintain the posture

How to stop CSS animation midway and maintain the posture

Preface

I once encountered a difficult problem. I needed to make a swinging house fall from a tower crane, but during the falling process, the house needed to maintain the swinging angle at the moment of falling. It was very difficult for me at that time. At first, I hoped to get the current swinging angle of the house and assign it to the house's transform:rotate() at the moment of falling, but this was too troublesome and would not be the optimal solution.

But in fact, only one attribute can solve this problem.

animation-play-state

1. CSS only

Use this property to pause an animation in its motion cycle, and start directly from the current frame the next time it starts. This is an animation property, which works on the animation property. You can use it in CSS or in JS, and it is equally convenient, at least... it is better than getting the angle and assigning it.

.xxx {
  animation-play-state: paused;  
  //Once this property is added, the CSS animation will be paused immediately and remain at the current frame}

.xxx {
  animation-play-state: running; 
  //Once this property is added, the CSS animation will start working immediately from the current frame;
}

You can add an animation to a page element and set it to appear when it is in the hover state.

 animation-play-state:paused

The animation will stop when your mouse moves over the element.

2. Use JS only

//When i is equal to 1, the media plays and the notes float. When i is equal to 0, the media pauses and the notes pause.
            if (i == 1) {
                right.style.animationPlayState = "paused"
                audio.pause();
                i = 0;
            } else {
                right.style.animationPlayState = "running";
                audio.play();
                i = 1;
            } 

insert image description here

This is the end of this article about how to stop and maintain CSS animation. For more information about stopping CSS animation, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Detailed explanation of mysql5.6 master-slave setup and asynchronous issues

>>:  Detailed explanation of Vue router routing guard

Recommend

React High-Order Component HOC Usage Summary

One sentence to introduce HOC What is a higher-or...

Node+express to achieve paging effect

This article shares the specific code of node+exp...

HTML table markup tutorial (22): row border color attribute BORDERCOLORLIGHT

Within rows, light border colors can be defined i...

MySQL Series 12 Backup and Recovery

Table of contents Tutorial Series 1. Backup strat...

Detailed explanation of Nginx Rewrite usage scenarios and code examples

Nginx Rewrite usage scenarios 1. URL address jump...

Why MySQL does not recommend using null columns with default values

The answer you often hear is that using a NULL va...

Angular framework detailed explanation of view abstract definition

Preface As a front-end framework designed "f...

Detailed explanation of Nginx passively checking the server's survival status

introduce Monitors the health of HTTP servers in ...

Analysis of the pros and cons of fixed, fluid, and flexible web page layouts

There is a question that has troubled web designe...

Summary of MySQL lock knowledge points

The concept of lock ①. Lock, in real life, is a t...

How to use lazy loading in react to reduce the first screen loading time

Table of contents use Install How to use it in ro...

Simple Implementation of HTML to Create Personal Resume

Resume Code: XML/HTML CodeCopy content to clipboa...