/****************
*
* IE-BUG:
* In IE, when setting the opacity attribute, the opacity attribute needs to be set in the element style to read the opacity value.
*
* obj: element object. attr: The attribute name surrounded by quotes. iTarget: attribute target value.
*
*****************/
function Move(obj,attr,iTarget){
clearInterval();//Close the previous timer to solve the problem of timer overlay when multiple Move() is called on the same object at the same time. Assigning each object calling Move() to its own timer to prevent multiple objects from using the same timer when calling Move() at the same time, resulting in related interference problems.
=setInterval(function(){
var cur=0;//Create a variable to store the value of the attr attribute every moment
if(attr=="opacity"){
//For the problem that the opacity attribute value is a floating point value in FF, the attribute value is rounded and converted to a floating point type. Multiply by 100 to make the opacity attribute value unified with IE as a percentage
cur=(parseFloat(getStyle(obj,attr))*100);
}else{
cur=parseInt(getStyle(obj,attr));//Convert the initial value of attributes other than opacity (width/fontSize/MarginLeft, etc.) to integer
}
var speed=(iTarget-cur)/10;//Create a decreasing speed variable. Implement variable speed change of attribute value
speed=speed>0?(speed):(speed);//From the browser to solve the problem that the browser ignores values less than 1px, causing a few pixels from the target value Itarget when the motion ends.
if(iTarget==cur){// When the target value is equal to the target value, the timer ends
clearInterval();
}else{
cur+=speed;//The current value cur plus the decreasing speed value
if(attr=="opacity"){
// Set opacity attribute values for IE and FF respectively
="alpha(opacity:"+cur+")"; //for IE
=cur/100; //for FF
}else{
[attr]=cur+"px"; //Add value cur+speed to the specified attribute attr
}
}
},30);
}
//getStyle() function is used to be compatible with IE and FF: Get the value of attributes in non-line styles of an object. obj: element object. name: attribute name.
function getStyle(obj,name){
if(){
return [name];//for IE
}else{
return getComputedStyle(obj,false)[name];//for FF
}
}