JS perfect motion framework and JS perfect motion framework

Source: Internet
Author: User

JS perfect motion framework and JS perfect motion framework

Function getStyle (obj, name) {if (obj. currentStyle) {return obj. currentStyle [name];} else {return getComputedStyle (obj, false) [name] ;}// note: In a multi-object motion frame, nothing can be shared! Otherwise, a problem occurs. add necessary variables to the attributes of an object. That is, the property is bound to the Motion Object: speed, other attribute values (such as transparency) function startMove (obj, json, fnEnd) // The Perfect motion frame // is converted to json, for example: startMove (oDiv, {width: 400, height: 400}) {clearInterval (obj. timer); obj. timer = setInterval (function () {var bStop = true; // key // assume that all values have reached for (var attr in json) // use a loop, package the original set of items in it. Every time the timer is executed, it will loop. The number of cycles depends on what is written in the json {var cur = 0; if (attr = 'opacity ') {cur = Math. round (parseFloat (getStyle (obj, attr) * 100); // because of this, a problem occurs, decimal number} else { Cur = parseInt (getStyle (obj, attr);} var speed = (json [attr]-cur)/6; speed = speed> 0? Math. ceil (speed): Math. floor (speed); if (cur! = Json [attr]) bStop = false; if (attr = 'opacity ') {obj. style. filter = 'Alpha (opacity: '+ (cur + speed) +') '; obj. style. opacity = (cur + speed)/100;} else {obj. style [attr] = cur + speed + 'px ';} if (bStop) // if all values have arrived, disable the timer {clearInterval (obj. timer); if (fnEnd) fnEnd () ;}, 30 );}



Note:

Obj ---------------> nodes that are in motion

Json ------------> which motion is to be performed, for example, {width: 300, height: 200} 300 and 200 are the target point?

Fu ---------------> the operation after the exercise ends, for example, a pop-up window or something appears after the exercise ends.



This JS perfect motion framework is from CSS2 ~

In CSS3, there is also a framework that surpasses the perfect motion frame ~ The framework can be used in CSS3 and CSS2 ~

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.