かんたん作成.com【HTML,CSS,JavaScript,CGI,PHP】

Click Here! ジャパンサーバ
容量50MB・アカウント50個、ドメイン取得料なし、データ転送料なし、詳しくはJP-SERVERまで。レンタルサーバーが格安の値段!
BB-Server
ドメイン取得、利用開始まで最短60分!!お申し込みからドメイン取得・セットアップまで最短1時間〜最長24時間でご利用いただけます!お急ぎの方はご入金後、電話にて連絡すると更にスピーディー!サーバー移行も早くて簡単!
Bfitセキュア
月額300円でSSLレンタルサーバーあなたのサイトの個人情報は、守られていますか?SSL通信(暗号化通信)を利用することで、あなたのサイトの個人情報を守ります。しかも、月額300円。

ランダムに動く画像(Math.random, pixelLeft, pixelTop)


<html>
<head>
<title>ランダムに動く画像</title>
   <script language="JavaScript">
   <!--
   xmin = 0;      // 左 動く範囲の設定
   ymin = 0;      // 上
   xmax = 670;      // 右
   ymax = 360;      // 下
   x = 0;
   y = 0;
   function move(){                  // 移動方向を決める
      rand = Math.floor(Math.random() * 10);
      if(img1.style.pixelLeft == xmin) {         // 左端の場合、右方向
         x = 0;
      }
      else if(img1.style.pixelLeft == xmax) {         // 右端の場合、左方向
         x = 1;
      }
      else if(rand == 0) {               // 乱数で決める
         x = Math.floor(Math.random() * 3);
      }
      if(img1.style.pixelTop == ymin) {         // 上端の場合、下方向
         y = 0;
      }
      else if(img1.style.pixelTop == ymax) {         // 下端の場合、上方向
         y = 1;
      }
      else if(rand == 0) {               // 乱数で決める
         y = Math.floor(Math.random() * 3);
      }
                           // 画像の移動
      if(x == 0) {                  // 右に移動
         img1.style.pixelLeft   = img1.style.pixelLeft   + 5;
      }
      else if(x == 1) {               // 左に移動
         img1.style.pixelLeft   = img1.style.pixelLeft   - 5;
      }
      if(y == 0) {                  // 下に移動
         img1.style.pixelTop   = img1.style.pixelTop   + 5;
      }
      else if(y == 1) {               // 上に移動
         img1.style.pixelTop   = img1.style.pixelTop   - 5;
      }
   }
   function tm(){                     // タイマー
      setInterval("move()",100);
   }
   //-->
   </script>
</head>
<body onLoad="tm()">
<img src="img.gif" ID="img1" STYLE="position:absolute;top:200;left:200">
</body>
</html>
実行する
当サイトはリンクフリーです。
	<a href="http://www.kantansakusei.com/">かんたん作成.com【HTML,CSS,JavaScript,CGI,PHP】</a>