Javascript chained motion framework-line-by-line code analysis allows you to easily understand the principle of motion
The so-called chain movement is a link. In fact, many of our sports refer to stages. The first stage is complete and the next stage starts to change. This chained motion frame is used to solve these problems. Let's take a look at the previous motion frame. The following is the Javascript code function getStyle (obj, name) {if (obj. currentStyle) {return obj. currentStyle [name];} else {return getComputedStyle (obj, null) [name];} function startMove (obj, attr, iTarget) {clearInterval (obj. time); obj. time = setInterval (function () {var cur = 0; if (attr = 'opacity ') {cur = Math. round (parseFloat (getStyle (obj, attr) * 100);} else {cur = parseInt (getStyle (Obj, attr);} var speed = (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)/100;} else {obj. style [attr] = cur + speed + 'px ';}}, 30);} is actually a stage-type motion frame, an object stops moving somewhere. So how can we achieve Chain movement? We are adding a fnEnd parameter. This is a function that will be called at the end of the motion. Of course, this function can be passed without being passed, so you need to make a judgment. It can be called only when it is passed in. The principle is: a motion is completed at the start of the next motion. In this way, we can complete the chain movement. Let's take a look at the code. <Style type = "text/css"> # div1 {width: 100px; height: 100px; 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', 300, function () {startMove (oDiv, 'height', 300 );});};} </script>