JQuery Animation Implementation CSS3 Animation sample Introduction _jquery

Source: Internet
Author: User
Tags setinterval
The JQuery animation works by changing the CSS style of an element from one state to another. CSS property values are gradually changed, so you can create animation effects. Only numeric values can create animations (such as "margin:30px"). String values cannot create animations (such as "background-color:red"). Please refer to the jquery effect-animate () method and the official tutorial for detailed usage.

Like CSS3 a lot of effect because it is not numeric, so there is no way directly through the animate () method to achieve. One feature of these methods, such as translate (), rotate (), scale (), skew (), matrix (), Rotatex (), Rotatey (), is that their values are mixed with characters and numbers. Therefore, we can not directly use the animate () method to dynamically modify their values to achieve the effect of animation.

If we implement CSS3 animations ourselves with JavaScript, then we can only implement them from the SetInterval () method, which is more complicated. In fact, the animate () method is based on the SetInterval () method to work, but can be easily set animation speed, can also be set to be uniform or variable speed. The second use of the Animate () method has a step parameter that sets the function to be executed for each stage of the animation. We can use a CSS value that does not affect the effect of the element to trigger the animate () method, and then modify the value we want to modify in the step callback function so that the animation can be implemented indirectly. Please see transform example:
Copy Code code as follows:

<div id= "box" ></div>
#box {
width:100px;
height:100px;
Position:absolute;
top:100px;
left:100px;
text-indent:90px;
background-color:red;
}

$ (' #box '). Animate ({textindent:0}, {
Step:function (NOW,FX) {
$ (this). CSS ('-webkit-transform ', ' Rotate (' +now+ ' deg) ');
},
Duration: ' Slow '
}, ' linear ');

Here use the Text-indent property to trigger the animation, because we do not have text here, so use text-indent without affecting the style effect of the elements, here can also use font-size and so on. The animation is then implemented using the rhythm generated by the animate () method. And so on, we can achieve a lot of results. For specific examples please refer here

Reference documentation
jquery Effect-animate () method
.animate ()

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.