Aloha Stockoverflow.
In advance, thank you! I am trying to modify my randomly changing background on my webpage, to add a FADE effect, so the change from 1 background to another is not so sudden and sharp. I have tried to search through the web endlessly for a solution to my issue, but it all points towards adding a jQuery plugin which I would preferably avoid if it is possible.
My working code is as follows and needs to have added some kind of fadein / fadeout effect.
<script type="text/javascript"> var num; var temp=0; var speed=5000; /* this is set for 5 seconds, edit value to suit requirements */ var preloads=[]; /* add any number of images here */ preload( 'images/bg1.jpg', 'images/bg2.jpg', 'images/bg3.jpg', 'images/bg4.jpg', 'images/bg5.jpg' ); function preload(){ for(var c=0;c<arguments.length;c++) { preloads[preloads.length]=new Image(); preloads[preloads.length-1].src=arguments[c]; } } function rotateImages() { num=Math.floor(Math.random()*preloads.length); if(num==temp){ rotateImages(); } else { document.body.style.backgroundImage='url('+preloads[num].src+')'; temp=num; setTimeout(function(){rotateImages()},speed); } } if(window.addEventListener){ window.addEventListener('load',rotateImages,false); } else { if(window.attachEvent){ window.attachEvent('onload',rotateImages); } } </script> Thank you very much for taking the time to look at it. :)