It is OK to be compatible with IE (Element.style.filter = ' alpha (opacity=value) ') and non ie (element.style.opacity=value).
Also, note that the value of ieopaciy is between 0~1, IE is 1-100.
Below, paste the code:
Copy Code code as follows:
/**
* @projectDescription animation (fade, Fade) class
* /**
* @projectDescription Kingkit UI
* @date 2010-6-1
* @author Kit.liao
* @copyright kingkit.com.cn
* @version 0.9.0
* @ Thank you: http://www.cnblogs.com/rubylouvre/archive/2009/09/16/1566699.html
* Use example: Fade: KUI.Animation.fadeIn (EL); Fade: KUI.Animation.fadeOut (EL)
*/
Kui. Animation = {
Fadein:function (ID) {
This.fade (ID, true);
},
Fadeout:function (ID) {
This.fade (ID, false);
},
Fade:function (ID, flag) {
var target = kui.get (ID);
Target.alpha = flag?1:100;
Target.style.opacity = (target.alpha/100);
Target.style.filter = ' alpha (opacity= ' + Target.alpha + ') ';
var value = Target.alpha;
(function () {
Target.style.opacity = (value/100);
Target.style.filter = ' alpha (opacity= ' + value + ') ';
if (flag) {
value++;
if (value <= 100) {
SetTimeout (Arguments.callee, 15);//Continue calling itself
}
}
else {
value--;
if (value >= 0) {
SetTimeout (Arguments.callee, 15);//Continue calling itself
}
}
})();
}
}
Package download