TOP /すぐに使えるJavaScript | ランダムに画像を配置 |
---|
同じ画像(アニメーションGIF)をランダムに配置します。
10個にしていますが、いくつでも指定できます。
<script type="text/javascript"><!-- Imgset="../star.gif"; //画像 Imgn=10; //配置の数 doc_width = document.body.clientWidth-30; doc_height= document.body.clientHeight-40; for (i=0; i < Imgn; i++){ xpx = Math.floor(doc_width*Math.random()); ypx = Math.floor(doc_height*Math.random()); star="<DIV STYLE='position:absolute;left:"+ xpx +"px;top:"+ ypx +"px;'><img src='"+Imgset+"'height=17 width=17></DIV>"; document.write(star); }/* himajin.moo.jp */ // --></script>