Javascript Chain Motion Framework--line by row analysis code, let you easily the principle of motion

Source: Internet
Author: User

The so-called chain movement, is tied up. Many of our movements actually refer to stages, the first phase is complete, and the next stage begins to move. This chain of motion framework is used to deal with these problems.

Let's take a look at the previous motion framework, and here's the JavaScript code

 function getStyle(obj, name) {    if(Obj.currentstyle) {returnObj.currentstyle[name]; }Else{returngetComputedStyle (obj,NULL) [name]; }} function startmove(obj, attr, ITarget) {Clearinterval (Obj.time); Obj.time = SetInterval ( function() {        varCur =0;if(attr = =' opacity ') {cur =Math. Round (parsefloat(GetStyle (obj, attr)) * -); }Else{cur =parseint(GetStyle (obj, attr)); }varSpeed = (itarget-cur)/6; Speed = speed >0?Math. Ceil (Speed):Math. Floor (speed);if(cur = = itarget)        {clearinterval (obj.time); }Else{if(attr = =' opacity ') {Obj.style.filter =' alpha (opacity= '+ cur + speed +' ) '; Obj.style.opacity = (cur + speed)/ -; }Else{Obj.style[attr] = cur + speed +' px '; }        }    }, -);}

In fact, he is the equivalent of a stage of the motion frame, an object movement to a place to stop. So how can we achieve chain-like movement?

We are adding a parameter fnend, this is a function, he will be called at the end of the movement.

Of course, this function can be passed without passing, so we need to make a judgment. It is called only when it is passed in.

The principle is: a movement is completed at the beginning of the next exercise.

This will be able to complete the chain movement, simple, let's look at the code.

<style type="Text/css"> #div1{width: px;  Height: + px;  background: red; }    </style><script src="js/move_lianshi.js" type="Text/javascript"  CharSet="Utf-8"></script>        <script type="Text/javascript">window.onload=function(){var odiv=document.getelementbyid ("Div1" 
      ); odiv.onmouseover=function(){ startmove (odiv,' width ',                     function(){ startmove (odiv,' height ',+);                });            }; }                        </script>    </head>    <body>        <div id="Div1">        </div>    </body>

Javascript:

 function getStyle(obj, name) {    if(Obj.currentstyle) {returnObj.currentstyle[name]; }Else{returngetComputedStyle (obj,NULL) [name]; }} function startmove(obj, attr, itarget,fnend) {Clearinterval (Obj.time); Obj.time = SetInterval ( function() {        varCur =0;if(attr = =' opacity ') {cur =Math. Round (parsefloat(GetStyle (obj, attr)) * -); }Else{cur =parseint(GetStyle (obj, attr)); }varSpeed = (itarget-cur)/6; Speed = speed >0?Math. Ceil (Speed):Math. Floor (speed);if(cur = = itarget) {clearinterval (obj.time);if(fnend) fnend (); }Else{if(attr = =' opacity ') {Obj.style.filter =' alpha (opacity= '+ cur + speed +' ) '; Obj.style.opacity = (cur + speed)/ -; }Else{Obj.style[attr] = cur + speed +' px '; }        }    }, -);}

This way, the div will widen and become taller.

We now have limitations on the framework of the movement, what is it?

So you can't move at the same time, which means I want the div to be big and wide at the same time. In the next update, we will solve this problem and introduce a perfect motion framework that supports most of the movement.

Please look forward to ~

Javascript Chain Motion Framework--line-by-row analysis of code, which makes it easy for you to move the principle of motion

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.