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