Hello everyone,
I'm quiet new so I hope I post it right.
I have this :
<!DOCTYPE html> <!-- This is just my HTML5-valid template. Make sure you set this up correctly for your personal needs -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<head>
<body>
<div id="menu">
livres<br>
travaux<br>
textes<br>
news<br>
infos<br>
contact<br>
</div>
<div id="image_aleatoire">
<img src="01_image_aleatoire/1.jpg" id="image1" style="position: fixed;" />
</div>
<div id="image_aleatoire">
<img src="01_image_aleatoire/3.jpg" id="image2" height="300px" style="position: fixed;" />
</div>
<script>
window.onLoad = Prep();
function Prep(){
window_Height = window.innerHeight;
window_Width = window.innerWidth;
image_Element = document.getElementById("image1");
image_Height = image_Element.clientHeight;
image_Width = image_Element.clientWidth;
availSpace_V = window_Height - image_Height;
availSpace_H = window_Width - image_Width;
var changeInterval = 2000; // Time has to be in miliseconds. So, 3000 is 3 seconds
setInterval(moveImage, changeInterval);
}
function moveImage(){
var randNum_V = Math.round(Math.random() * availSpace_V);
var randNum_H = Math.round(Math.random() * availSpace_H);
image_Element.style.top = randNum_V + "px";
image_Element.style.left = randNum_H + "px";
}
window.onLoad = Prep();
function Prep(){
window_Height = window.innerHeight;
window_Width = window.innerWidth;
image_Element = document.getElementById("image2");
image_Height = image_Element.clientHeight;
image_Width = image_Element.clientWidth;
availSpace_V = window_Height - image_Height;
availSpace_H = window_Width - image_Width;
var changeInterval = 2000; // Time has to be in miliseconds. So, 3000 is 3 seconds
setInterval(moveImage, changeInterval);
}
function moveImage(){
var randNum_V = Math.round(Math.random() * availSpace_V);
var randNum_H = Math.round(Math.random() * availSpace_H);
image_Element.style.top = randNum_V + "px";
image_Element.style.left = randNum_H + "px";
}
</script>
</body>
</html>
link : http://davidexcoffier.com/test.html
Which works very well for one image.
Do you have any ideas how to arrange the script for several images ?
I've tried different way pour it's too complicated and not working.
Thanks in advance