Firstly this is a school project with the requirements that no outside libraries can be used (such as JQuery) so only vanilla html, css and javascript. I am trying to create an image that will transition to another image after x seconds.
$(document).ready(function() {
var timer;
var sec = 1;
var timeField = document.getElementById("time");
var photo = document.getElementById("html_photo");
timeField.innerHTML = "1";
var photo_current = ["http://www.drodd.com/images15/1-15.jpg","http://www.drodd.com/images15/2-23.jpg","http://www.drodd.com/images15/3-12.jpg"];
function update() {
sec++;
timeField.innerHTML = sec;
if (sec == 30) sec = 0;
}
function changeImage() {
if (sec == 1) {
photo.src = photo_current[1];
} else if (sec == 3) {
photo.src = photo_current[2];
} else if (sec == 5) {
photo.src = photo_current[3];
}
}
function start() {
timer = setInterval(function() {
update()
changeImage()
}, 1000);
}
start();
});
<body window.onload=function() {start();}>
<div id="time"><span>1</span></div>
<img src="http://www.drodd.com/images15/1-15.jpg" id="hml_photo">
</body>
Thank You :)