I have a function change_background()
that I call from document.onload
through a setInterval( change_background(), 5000 );
to change the background of my heading every 5sec's.
Where I'm stuck in writing my function is:
How can I increment my num
var every time its called?
function change_background(){
var element = document.getElementsByClassName('top');
element[0].style.backgroundImage = 'url( "media/image' + num + '.jpg" )';
//when num gets greater than the amount of images
if( num > 2 ){
num = 0;
}
}//end change_background()
I'm just messing around trying to achieve this effect. Is this even possible the way I'm doing it, am I going the wrong way about it?