JavaScript Motion Framework

Source: Internet
Author: User

Motion Frame
How to use JSON to pass parameters
function Sportframe (obj,json,fun) {
var timer;
Clearinterval (Obj.timer);
Obj.timer=setinterval (function () {
var stop=true;
for (var name in JSON) {
var val=0;
Judging is not transparency
if (name== ' opacity ') {
Val=math.round (parsefloat (CSSStyle (obj,name)) *100);
}else{
Val=parseint (CSSStyle (obj,name));
}
Buffering speed
var speed= (Json[name]-val)/10;
Speed=speed>0? Math.ceil (Speed): Math.floor (speed);
if (Val!=json[name]) {
if (name== "opacity") {
Obj.style.filter= ' alpha (opacity: ' +val+speed+ ') ';//ie
obj.style.opacity= (val+speed)/100;
}else{
CSSStyle (obj,name,val+speed+ ' px ');
}
}
}
Determine if the end is reached
if (Stop) {
Clearinterval (timer);
if (fun) {
Fun ();
}
}
},30);
}

Get property value and set property value frame
function CSSStyle (obj,prop,value) {
Style can only get the value written in the HTML tag written in the Style property (style= "..."),
Unable to get the attribute defined in <style type= "Text/css" >
The Currentstle,getcomputedstyle method can get inline or external styles
Get style
if (arguments.length==2) {
if (Obj.currentstyle) {
return Obj.currentstyle[prop]; Ie
}else{
Return getComputedStyle (Obj,false) [prop]; Kindle
}
}
Set style
else{
if (arguments.length==3) {
Obj.style[prop]=value;
}
}
}

JavaScript Motion Framework

Related Article

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.