CSS3 animation properties: Introduction to the Animation property
不言
Release: 2018-08-09 16:21:04
Original
2991 people have browsed it
The content of this article is about how to use CSS3 to create animation attributes: The introduction of the Animation attribute has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
There are three properties related to animation in the CSS3 properties:Transform,Transition,Animation; we have finished learning Transform and Transition together. Let us implement some basic animation effects on elements. I think these are enough to excite everyone for a while. Today we take advantage of this enthusiasm to continue learning the third animation attribute Animation. From the literal meaning of Animation, we will I know what "animation" means. But Animation in CSS3 is different from Canvas drawing animation in HTML5. Animation is only applied to DOM elements that already exist on the page, and it is different from the animation effects produced by Flash, JavaScript and jQuery, because we use CSS3 Animation can save us from complex js and jquery codes when making animations (which is very happy for people like me who don’t understand js). There is just one shortcoming. We can use Animation to create what we want. There are some animation effects, but they are a bit rough. If you want to make better animations, I think you should use flash or js. Although the animation produced by Animation is simple and rough, I think it still cannot reduce our enthusiasm for learning it.
Before we start introducing Animation, we need to first understand a special thing, that is "Keyframes", we call it "Keyframes", friends who have played flash may be familiar with this thing . Let's take a look at what this "Keyframes" is. When we used transition to create a simple transition effect earlier, we included initial attributes and final attributes, a start action time and a continuation action time as well as the transformation rate of the action. In fact, these values are all intermediate values. If we want The control is more detailed, for example, what actions do I want to perform in the first time period, and what actions do I want to perform in the second time period (switching to flash, it means what actions I want to perform in the first frame, and what actions I want to perform in the second frame What action), it is difficult for us to use Transition to achieve this. At this time, we also need such a "key frame" to control. Then CSS3 Animation uses the "keyframes" attribute to achieve this effect. Let's take a look at Keyframes first:
Keyframes have their own syntax rules. Their naming starts with "@keyframes", followed by the "name of the animation" plus a pair of curly braces. "{}", in brackets are some style rules for different time periods, a bit like our CSS style writing. For a style rule in "@keyframes" that is composed of multiple percentages, such as between "0%" and "100%", we can create multiple percentages in this rule, and we give each percentage a Elements with animation effects need to be added with different attributes, so that the elements can achieve a constantly changing effect, such as moving, changing element color, position, size, shape, etc. However, one thing to note is that we can use "fromt" and "to" represent where an animation starts and ends. In other words, "from" is equivalent to "0%" and "to" is equivalent to "100%". It is worth mentioning that, Among them, "0%" cannot omit the percent sign like other attribute values. We must add the percent sign ("%") here. If not, our keyframes will be invalid and will have no effect. Because the unit of keyframes only accepts percentage values.
Keyframes can be specified in any order to determine the key position of the Animation animation change. The specific grammar rules are as follows:
Among them, IDENT is an animation name. You can choose it casually. Of course, it is better to be more semantic. Percentage is the percentage value. , we can add many such percentages. Properties is the property name of css, such as left, background, etc., and value is the attribute value of the corresponding property. It is worth mentioning that our from and to correspond to 0% and 100% respectively. We have mentioned this before. So far, only browsers with webkit core support animation animation, so I need to add the -webkit prefix to the above. It is said that Firefox5 can support the animation animation property of CSS3.
Let's take a look at an example from the W3C official website
Here we define an animation called "wobble". His animation starts from 0% and ends at 100%, and there are still experiences from it There are two processes of 40% and 60%. The specific meaning of the above code is: when the wobble animation is at 0%, the element is positioned at the left position of 100px, the background color is green, and then at 40%, the element transitions to the left position of 150px and the background color is green. The color is orange. At 60%, the element transitions to the position where the left is 75px, and the background color is blue. Finally, when the animation ends at 100%, the element returns to the starting point where the left is 100px, and the background color becomes red. Assume that we only give this animation 10s of execution time, then the execution status of each segment is as shown in the figure below:
The above is the detailed content of CSS3 animation properties: Introduction to the Animation property. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn