Skip to content

Instantly share code, notes, and snippets.

@tjh
Created August 17, 2010 13:59
Show Gist options
  • Save tjh/530040 to your computer and use it in GitHub Desktop.
Save tjh/530040 to your computer and use it in GitHub Desktop.
var delay = 5000;
var transition = 40;
var imageContainer = 'jw-sir';
var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;
function init() {
if(!d.getElementById || !d.createElement)return;
imgs = d.getElementById(imageContainer).getElementsByTagName("img");
for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
imgs[0].style.display = "block";
imgs[0].xOpacity = .99;
setTimeout(so_xfade,delay);
}
# -----------------------------------------
# Crossfade two images
# -----------------------------------------
function so_xfade() {
cOpacity = imgs[current].xOpacity + .3;
nIndex = imgs[current+1]?current+1:0;
nOpacity = imgs[nIndex].xOpacity;
cOpacity-=.05;
nOpacity+=.05;
imgs[nIndex].style.display = "block";
imgs[current].xOpacity = cOpacity;
imgs[nIndex].xOpacity = nOpacity;
setOpacity(imgs[current]);
setOpacity(imgs[nIndex]);
if(cOpacity<=0) {
imgs[current].style.display = "none";
current = nIndex;
setTimeout(so_xfade,delay);
} else {
setTimeout(so_xfade,transition);
}
function setOpacity(obj) {
if(obj.xOpacity>.99) {
obj.xOpacity = .99;
return;
}
obj.style.opacity = obj.xOpacity;
obj.style.MozOpacity = obj.xOpacity;
obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}
}
window.onload = function ( e ) {
init();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment