I'm using this code to display two images on a particular page:
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<style>
#mapinha {
position: relative;
top: 0;
left: 0;
}
#mapa_big {
position: relative;
top: 0;
left: 0;
}
#mapa_movimento {
position: absolute;
top: 0px;
left: 0px;
}
</style>
</head>
<body>
<div id="mapinha">
<img id="mapa_big" src="http://triviapw.hiperportal.blog.br/elysium_old/images/floresta_yujia_big_v2.jpg"/><imgid="mapa_movimento" src="" />
</div>
</body>
</html>
Soon after the tag close the 'body' tag I'm using this script to determine which image will be displayed within the ID="movemap" according to the current minute:
<script type="text/javascript">
var currentTime = new Date().getMinutes();
if (44 <= currentTime && currentTime < 45) {
if (document.getElementById) {
document.getElementById("mapa_movimento").src = "http://triviapw.hiperportal.blog.br/elysium_old/images/moves/floresta_yujia_v2_move_001.png";
}
}
if (46 <= currentTime && currentTime < 47) {
if (document.getElementById) {
document.getElementById("mapa_movimento").src = "http://triviapw.hiperportal.blog.br/elysium_old/images/moves/floresta_yujia_v2_move_002.png";
}
}
else {
if (document.getElementById) {
document.getElementById("mapa_movimento").src = "http://triviapw.hiperportal.blog.br/elysium_old/images/moves/floresta_yujia_v2_move_003.png";
}
}
</script>
I want to use a different image for each minute ... and that's ok, the problem is to have the function repeated every 60 seconds to change the displayed image to the user.
For example, if you access the page at 05:44 hours, the image "... 001.png" will be displayed, but when you change the time to 05:55, the image to be displayed should be "... 002.png ".
To solve the problem, I tried to use 'setInterval' and 'setTimeout', but it did not work, I believe that it is the lack of the name of this function that changes the images, however I could not make it work when I changed it to: p>
<script type="text/javascript">
function mudarImagem(){
var currentTime = new Date().getMinutes();
if (44 <= currentTime && currentTime < 45) {
if (document.getElementById) {
document.getElementById("mapa_movimento").src = "http://triviapw.hiperportal.blog.br/elysium_old/images/moves/floresta_yujia_v2_move_001.png";
}
}
if (46 <= currentTime && currentTime < 47) {
if (document.getElementById) {
document.getElementById("mapa_movimento").src = "http://triviapw.hiperportal.blog.br/elysium_old/images/moves/floresta_yujia_v2_move_002.png";
}
}
else {
if (document.getElementById) {
document.getElementById("mapa_movimento").src = "http://triviapw.hiperportal.blog.br/elysium_old/images/moves/floresta_yujia_v2_move_003.png";
}
}}
</script>
Thank you.