This will do the trick:
function _(el) {
if (!(this instanceof _)) {
return new _(el);
}
this.el = document.getElementById(el);
}
_.prototype.fade = function fade(type, ms) {
var isIn = type === 'in',
opacity = isIn ? 0 : 1,
interval = 50,
duration = ms,
gap = interval / duration,
self = this;
if(isIn) {
self.el.style.display = 'inline';
self.el.style.opacity = opacity;
}
function func() {
opacity = isIn ? opacity + gap : opacity - gap;
self.el.style.opacity = opacity;
if(opacity <= 0) self.el.style.display = 'none'
if(opacity <= 0 || opacity >= 1) window.clearInterval(fading);
}
var fading = window.setInterval(func, interval);
}
_('myButton').fade('out', 500);
From here on out you can extend your _
object with any jQuery-like function.