79
rated 0 times
[
85]
[
6]
/ answers: 1 / hits: 5445
/ 11 Years ago, wed, december 18, 2013, 12:00:00
I think I must be missing something very obvious. Using this code I want to count up and trigger a background change on a timer; however it doesn't pass the variable, each time the timer calls the function it is passing a undefined variable.
Worth noting:
- Looked at the consol - no errors
- I know Jquery would arguably be better but the site can't have jquery due to some nasty legacy issues (thats a whole other question)
The Code
<script>
/* Get the body element */
var body = document.getElementsByTagName('body')[0];
/* Call the function */
changebackground();
/* Set the starting count */
var changecount = 1;
/* Change function */
function changebackground(changecount) {
if(changecount=1){
body.style.backgroundImage = 'url(/templates/images/background_1.jpg)';
changecount = 2;
}
else if (changecount=2) {
body.style.backgroundImage = 'url(/templates/images/background_2.jpg)';
changecount = 3;
}
else {
body.style.backgroundImage = 'url(/templates/images/background_3.jpg)';
changecount = 1;
}
setInterval(function(changecount){changebackground();},3000);
}
</script>
More From » function