Created
August 17, 2010 13:59
-
-
Save tjh/530040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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