Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dissecting jQuery's Fade Animation
function $(id) {
var $ = document.getElementById(id);
var opacityTo = function (elm, v) {
elm.style.opacity = v/100; // CSS3
elm.style.MozOpacity = v/100; // FF
elm.style.KhtmlOpacity = v/100; // Safari
elm.style.filter=" alpha(opacity ="+v+")"; // IE
};
$.fade = function (delay, callbk, out) {
var _this = this;
// for ie
_this.style.zoom = 1;
_this.style.display="block";
for (var i = 1; i <= 100; i++) {
(function(j) {
setTimeout(function() {
if (out == true) {
j = 100 - j;
}
opacityTo(_this, j);
if (j == 100 && callbk != undefined) {
callbk.call(_this);
}
else if (out == true && callbk != undefined && j == 0) {
callbk.call(_this);
}
}, j*delay/100);
})(i);
}
};
$.fadein : function(elm, delay, callbk) {
$.fade(elm, delay, callbk, false);
};
$.fadeout : function(elm, delay, callbk) {
$.fade(elm, delay, callbk, true);
};
return $;
})();
@soofaloofa-zz

This comment has been minimized.

Copy link
Owner Author

soofaloofa-zz commented May 18, 2011

Usage:
$("imgid").fadeIn(1000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.