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