Page four ways to achieve animation

Face questions manuscript

Pages achieve animation of four ways:

So far commonly used pages way to achieve animation there are four, namely,   

    1 transition transition animation to achieve animation effects

 2 animation css animation to achieve animation effects

3 native js rely on timers to encapsulate animation

4 by the built-in animation jQuery (three groups based animation, and a custom animation) to achieve the effect of

Wherein the transition transition animation, may be between two states of a page element, automatically be animated

Very simple and lightweight, by setting the transition-propery, duration, timing-function, delay can be very easy to control a variety of mainly animation; of course, the disadvantage is also very obvious,

1 transition transition animation always starts from the current state, destined for a target state, that is, switching between the two states; it is difficult to make transition to implement some complex animation; transition control style is a little particular about; positioning can be instant place, and transform it not; so in many cases two state transition control element, in fact, did not we think of easy

2 transition animation, in the face of display: none and display: block these two common state switchover, there is no effect. Including between the two states hope to add on additional properties change is not effective; in effect a state transition state must be displayed on the page

3 and css animation has always been a problem to achieve that property must be consistent, such as our position with the positioning properties habits, generally from which side near which side. Such as stickers left on a left, stick to the right to use right; at this point, transition to achieve animation actually still need some calculations, this is not obvious in the JS animated inside, in fact, because JS animation (especially native), stressed to achieve animation journey through cumulative, rather than the beginning and end of the state;

animation animation style c3 page is provided by eight property is very flexible, and @keyframe custom status animation the way, you can achieve a variety of automatic animation;

Use animation animate reciprocating motion, than js be convenient; JS Jquery must have that kind of animation queue was more convenient

And on a variety of one-way movement of the animation, we generally may like to use JS to achieve, but in fact to dynamically add animation by class name, can be achieved quite good results;

Very common example is the page box flying into effect, we hope these boxes flying into as stable as possible, and preferably just an animation effect. In fact, you can set a placement animation class name (this movie, I personally like to use relative positioning to do, because the relative positioning, it must be top0 animated destination and left0. Only need to set the starting position on it , and you can save and transform properties,

Native JS rely on animation timer to achieve, in fact, control the properties of a box, so the box step by step, reach set destination within a certain time;

Common problem is a timer issue, in order to ensure the timer will not conflict with each other. The general practice is directly in front of the animation code, first clear look at the existing timer. This approach can solve the problems between conflicting animation, but not conducive to control the order of execution of code, such as we need to do a little something at the time of the end of the animation; in this case are generally clear timer judge writes a callback function, then perform this function so that when the animation reaches the end. It is also easier to adjust than something with a delay like better control; but if we removed the timer, the callback function will never be implemented;

And repeatedly turn off timer, there will be animation Caton problems. This is because the state does not run the timer start

(If in the animated timer and mount what hope there is a certain order of execution of code, then remove the timer will never executed)

Another animation problem, the problem is the mechanism of animation events will trigger exposed; pull-down menu as an example, even if a general rise and the drop-down menus are animated, because the menu animations are generally faster, so leaving the circumstances of the incident magnifying glass case arise, that is, inside the parent element into the child element, triggering the parent element, child elements into the event, and then enter the event bubbling to the parent element; in the animation will have a significant exhumation

And if this is only a drop-down menu animation, leave instantly disappear, then this feature is definitely the type of disaster. From the animation simply do not fit this case. This is why we have Mouseenter savior level events; but the conventional approach is not impossible, I personally realized by way of bypassing the animation effect; that is the way a magnifying glass effect, with the Show Hidden moment to replace certain behaved animation, animation can be avoided exhumation, but the entire event will trigger the need for well-designed. This is not animation there would be no problem, so I think it should be said in the animation inside

Animation JQuery provides a very easy to use, especially custom animation;

But the basis of the animation is actually quite common. See a lot of animation effects are similar basis; but there is need to pay attention to the difference between the two front and Toggle animation. Toggle animation can continue to achieve the effect of termination, and basic animation not. Basic animation can ensure the effectiveness of the entire animation trigger must be desired, but there is a risk TOGGLE be the opposite of the

JQuery custom animation is not without risk, especially after extensive spend stop method. If you stop a movie, then this custom animation inside the callback function is not performed if the key effect of this callback function is related to the performance of such sequence diagram of the carousel and the like; we must address the root causes of the problem from the (also the point is to get rid of the user so fast!)

Guess you like

Origin www.cnblogs.com/yeanling/p/11071830.html