1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
<head>
<script>
function affiche(){
// recuperation de la resolution de l'ecran chez l'utilisateur
largeur = screen.width;
hauteur = screen.height;
// positionnement aleatoire
posx = Math.round(Math.random()*largeur);
posy = Math.round(Math.random()*hauteur);
// recuperation de l'element div servant a afficher l'image
elementDivImage = document.getElementById("elemImage");
// ajustement de l'attribute style, notament left et top
elementDivImage.setAttribute("style","position:absolute; left:"+posx+"px; top:"+posy+"px; width:160; height:120; z-index:1");
}
</script>
</head>
<body onLoad="affiche()">
<div id="elemImage" style="">
<img src="images/1.jpg" name="image" width="160" height="120" id="image">
</div>
<div id="layer2" style="">
<a href="#" onClick= "affiche();">une image a position aleatoire?</a>
</div>
</body> |
Partager