Animation several more fun properties (alternate, and Animation-fill-mode)

Source: Internet
Author: User

<! DOCTYPE html>
<style>
Div
{
width:100px;
height:100px;
background:red;
position:relative;
Animation:mymove 5s Infinite;
-moz-animation:mymove 5s Infinite; /* Firefox */
-webkit-animation:mymove 5s Infinite; /* Safari and Chrome */
-o-animation:mymove 5s Infinite; /* Opera */
Animation-fill-mode:both;
}

@keyframes Mymove
{
from {top:0px;}
to {top:200px;}
}

@-moz-keyframes mymove/* Firefox */
{
from {top:0px;}
to {top:200px;}
}

@-webkit-keyframes mymove/* Safari and Chrome */
{
from {top:0px;}
to {top:200px;}
}

@-o-keyframes mymove/* Opera */
{
from {top:0px;}
to {top:200px;}
}
</style>
<body>

<p><b> Note:</b> This example is not valid in Internet Explorer. </p>

<div></div>

</body>

Http://www.w3school.com.cn/tiy/t.asp?f=css3_keyframes

You can see a red square, moving from the top to the bottom, and then quickly back up, then press animation:5s, from the top of the movement to the bottom, so that the cycle. The key in this is keyframes, which defines the animation, and Animation:infinite 5s; The animation effect is defined, where infinite represents the loop, the process of the cycle. Get rid of this, we see the Red Square slowly down and then quickly back to the top and then no longer move.

Then we want to make the square movement once left in the following, what should be done, this is the role of Animation-fill-mode, I today on the Teambition website to see their navigation bar effect is to use this, according to W3, Animation-fill-mode has four properties, None,forwards,backwards,both, where none and forwards allow the motion object animation to return to the state before the animation, Both and forwards, in turn, allow the moving object to retain the effect of the last frame before the end of the animation, so if we want the square to move once and then stop below, we need to use the Animation-fill-mode property.

and alternate is to achieve round-trip effect, we in the realization of pendulum clock animation often may need this, we can not hope that pendulum clocks from left to right is a we determine the frequency, from right to left is a rapid state, not consistent. This will be visually compromised, and you can experiment on this red Square. For example Animation:mymove 5s infinite; animation:mymove 5s infinite Alternate;

To actually look at the effect.

If you have any questions, please let me know in time. We all study together.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Animation several more fun properties (alternate, and Animation-fill-mode)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.