1
I am using this code to display two images on a given 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" />
<img id="mapa_movimento" src="" />
</div>
</body>
</html>
Soon after the tag closes the tag 'body' I am using this script to determine which image will be displayed inside the ID="map_movement" 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 intend to use a different image for each minute... and this is already ok, the problem is to have the function repeat every 60 seconds to change the image displayed to the user.
For example, if you go to 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 using 'setInterval' and 'setTimeout', but it did not work, I believe it is the lack of the name of this function that changes the images, but I could not make it work when I changed to:
<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.
It worked perfectly, thank you!
– Wesley