Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to control the animation effect of HTML elements in CSS3

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report