• <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>

    如何用html+css+javascript寫一個簡易紅綠燈

    用html+css+javascript寫一個簡略單純紅綠燈

    東西/原料

    • 利用windows自帶記事本

    方式/步調

    1. 1

      新建一個.html文件,用記事本打開。

    2. 2

      在記事本中復制添加以下內容并保留:

      <html>

         <head>

      <title>紅綠燈</title>

      <style>

      #div1 div{

      width:200px;

      height:200px;

      background:pink;

      border:2px solid blue;

      float:left;

      margin:10px;

      border-radius:100%;

      }

      #div1{

         width:680px;

         height:220px;

         background:pink;

         border:2px solid black;

         margin-left:25%;

      }

      </style>

      <script>

         window.onload = function(){

      var divs = document.getElementById('div1').getElementsByTagName('div');

      var index = 0;

      var color = ['red','yellow','green'];

      setInterval(f1,1000);

      f1();

      function f1(){

         for(var i = 0; i < 3; i++){

             divs[i].style.background = 'gray';

         }

         divs[index].style.background = color[index];

         index == 2 ? index = 0 : index++;

      }

         }

      </script>

         </head>

         <body>

      <h1 style="text-align:center;margin-top:10%;">紅綠燈</h1>

      <div id="div1">

      <div></div>

      <div></div>

      <div></div>

      </div>

         </body>

      </html>

    3. 3

      用瀏覽器打開此文件

    4. 4

      結果截圖:

    • 發表于 2018-08-22 00:00
    • 閱讀 ( 913 )
    • 分類:其他類型

    你可能感興趣的文章

    相關問題

    0 條評論

    請先 登錄 后評論
    聯系我們:uytrv@hotmail.com 問答工具
  • <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>
    久久久久精品国产麻豆