I can't find any javascript solution that is simple to integrate to my code. And i don't want to just copy paste i would like to understand.
I have a basic javascript function that changes the images every 3 seconds and i would like to make the images fade when transitioning to make it look a little bit nicer.
JS:
<script type = "text/javascript">
function nextImage() {
x = (x === imgArray.length - 1) ? 0 : x + 1;
document.getElementById("img").src = imgArray[x];
}
function begintimer() {
setInterval(nextImage, 3000);
}
var imgArray = [], x = -1;
imgArray[0] = "images/test.jpg";
imgArray[1] = "images/bg.jpg";
</script>
HTML:
<body onload = "begintimer()">
<div id="section1">
<img id="img" src="images/bg.jpg"/>
</div>
</body>
Thanks for your help!