Questo codice mi permette di cambiare l'immagine di sfondo della pagina ogni tot secondi:
1 - il problema è che l'immagine viene ripetuta mentre a me servirebbe fissa al centro. Cosa dovrei aggiungere o modificare nel codice per far ciò?
2 - si potrebbe fare in modo che l'immagine cambi solo quando viene ricaricata la pagina anzicchè ogni tot secondi?
Grazie mille!!
Codice:
<script type="text/javascript">
var bgImages = new Array();
bgImages.push("1.jpg");
bgImages.push("2.jpg");
bgImages.push("3.jpg");
bgImages.push("4.jpg");
function LoadRandomBackground()
{
var randomImageIndex = Math.floor(Math.random()*bgImages.length)
document.body.background = bgImages[randomImageIndex];
}
function StartBackgroundRefreshTimer()
{
var timer = setInterval('LoadRandomBackground()',4000); // 4 seconds
}
</script>
</head>
<body onload="LoadRandomBackground(); StartBackgroundRefreshTimer()">
</body>
1 - il problema è che l'immagine viene ripetuta mentre a me servirebbe fissa al centro. Cosa dovrei aggiungere o modificare nel codice per far ciò?
2 - si potrebbe fare in modo che l'immagine cambi solo quando viene ricaricata la pagina anzicchè ogni tot secondi?
Grazie mille!!