我想在加載頁面的同時淡入多個圖像。就像這個網站那樣:http://www.struckaxiom.com/work。我有腳本只在一個圖像上執行,但我想要包含更多圖像。 這是單張照片腳本。請幫忙。多個圖像淡入onLoad(同時)
document.write("<style type='text/css'>#thephoto {visibility:hidden;}</style>");
function initImage() {
imageId = 'thephoto'
image = document.getElementById(imageId);
setOpacity(image, 0);
image.style.visibility = "visible";
fadeIn(imageId,ImageId2,0);
}
function fadeIn(objId, opacity) {
if (document.getElementById) {
obj = document.getElementById(objId);
if (opacity <= 100) {
setOpacity(obj, opacity);
opacity += 10;
window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
}
}
}
function setOpacity(obj, opacity) {
opacity = (opacity == 100)?99.999:opacity;
// IE/Win
obj.style.filter = "alpha(opacity:"+opacity+")";
// Safari<1.2, Konqueror
obj.style.KHTMLOpacity = opacity/100;
// Older Mozilla and Firefox
obj.style.MozOpacity = opacity/100;
// Safari 1.2, newer Firefox and Mozilla, CSS3
obj.style.opacity = opacity/100;
}
window.onload = function() {initImage()}
// -->
</script>
謝謝!
AFAIC,這可以解決這個問題,但如果您在加載之前沒有透露圖片,它會更好看。 – Kranu 2011-02-25 08:43:45
謝謝@Kranu我忘了更新CSS,我的錯誤。 :/ – 2011-02-25 08:47:02
+1 http://jsfiddle.net/e863X/2/ – Kranu 2011-02-25 08:50:29