Multi-Object motion JavaScript function encapsulation

Source: Internet
Author: User

function Startmove (obj, JSON, func) {
Clearinterval (Obj.timer);
Obj.timer = setinterval (function () {

var bstop = true;

Take out the initial value of the attribute
for (Var attr in JSON) {
var icur = 0;
if (attr = = "opacity") {
Icur = parsefloat (GetStyle (obj, attr)) * 100;
}else{
Icur = parseint (GetStyle (obj, attr))
}
var speed = (json[attr]-icur)/8; 8 scaling factor, cushioning the best scaling factor for motion effects
Speed = speed > 0? Math.ceil (Speed): Math.floor (speed);

The program cannot continue as long as there is a value that does not reach the specified value
if (icur! = Json[attr]) {
Bstop = false;
}
if (attr = = "opacity") {
Obj.style.filter = "Alpha (opacity:" + (Icur + speed) + ")";
Obj.style.opacity = (icur + speed)/100;
}else{
OBJ.STYLE[ATTR] = icur + speed + "px";
}
}
if (bstop) {
Clearinterval (Obj.timer);
if (func) {
Func ();
}
}
}, 30);
}

Get non-inline styles
function GetStyle (obj, attr) {
if (Obj.currentstyle) {
return obj.currentstyle[attr]; IE9 below
}else{
return getComputedStyle (obj) [attr]; IE9 and Standard Browser
}
}

Multi-Object motion JavaScript function encapsulation

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.