Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to control the animation effect of HTML elements in CSS3

Shulou Source: shulou.com Published: 2022-05-31 13:22:14 10月02日 Update

This article introduces the relevant knowledge of "how to control the animation effects of HTML elements in CSS3". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Control of element transform

The code is as follows:

.showbox {float: left; margin:4em 1em; width:100px; height:60px; borer:2px solid green; background-color:#000; text-align:center;-webkit-transition: 1s ease-in-out; transition:1s ease-in-out;} .sliderright: hover {- webkit-transform:translate (30em, 0); transform:translate (30em, 0);}

In CSS3, an element can have the following transform-control attribute:

-webkit-transform: translate;-webkit-transform: rotate (30deg);-webkit-transform: scale (1.5)

Through proper transformation, we can finally change the position of the element into the effect we need.

Animation properties of 2.CSS3

All elements in CSS3 are controlled by the following attributes

The code is as follows:

-webkit-transition: 1s ease-in-out

In fact, this css attribute controls how to change those values when the style of an element changes. Some style that can change continuously, such as opacity,color,width, can be animated under the control of this attribute.

3. Multi-time Control of Animation

We can control the animation point by point and put another example:

The code is as follows:

Box {position:relative; width:100px; height:100px; left:0; top:0; background:blue;-webkit-transition-property: width, height, left, top, background,-webkit-transform;-webkit-transition-duration: 1s, 1s, 2s, 2s, 1s, 1s;-webkit-transition-timing-function: ease-in-out, ease-in-out, ease-out, ease-in, linear, ease-in-out;-webkit-transition-delay:1s, 1s, 0s, 0s, 1s .box: hover {width:50px; height:50px; left:150px; top:150px; background:red;-webkit-transform:rotate (360deg);}

In the above example,-webkit-transition-property controls which style attributes are needed for the animation, duration and delay control the time node, and timeing function controls whether or not to fade in and out.

4. How to get the hover action of one element to trigger the animation of another element?

We can use some link symbols of the CSS attribute, such as the example below, using the ~ sign, when the hover action of label1 is triggered, it will affect the label2, and then trigger the animation of label2

Box1 {position:absolute; background:red; width:100px; height:100px; top:0; left:0;} .box1: hover ~ .box2 {left:500px;} .box2 {position:absolute; width:100px; height:100px; left:120px; top:0; background:blue;-webkit-transition: 1s ease-in-out;} "how to control the animation effects of HTML elements in CSS3". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Control elements animation attributes effects code examples facets changes content actions reality time time more knowledge practicality appropriateness learning and then Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia Redmi vpn macOS