Advertisement
1xptolevitico69

Javascript animation ( Traffic Lights )

Jul 15th, 2022 (edited)
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.65 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <style>
  9.     body {
  10.       overflow: hidden;
  11.     }
  12.  
  13.     #lights {
  14.       border: 5px solid;
  15.       width: 90px;
  16.       background-color: snow;
  17.       border-radius: 8px;
  18.       padding: 10px;
  19.       position: absolute;
  20.       left: -80px;
  21.       top: -80px;
  22.     }
  23.  
  24.     #box {
  25.       position: relative;
  26.       margin: 100px 200px;
  27.       width: 100px;
  28.       height: 400px;
  29.       border-radius: 0 60px 0 0;
  30.       border: 20px solid;
  31.       border-left: none;
  32.       border-bottom: none;
  33.     }
  34.  
  35.     .color {
  36.       margin: 5px 15px;
  37.       border: 30px solid;
  38.       border-radius: 50%;
  39.       width: 0;
  40.     }
  41.   </style>
  42. </head>
  43.  
  44. <body>
  45.  
  46.   <section id='box'>
  47.     <section id='lights'>
  48.       <div class='color'></div>
  49.       <div class='color'></div>
  50.       <div class='color'></div>
  51.     </section>
  52.   </section>
  53.  
  54.   <script>
  55.     x = document.getElementsByClassName("color");
  56.     colors = ["red", "orange", "green"];
  57.     setTimeout(traffic = () => {
  58.       x[2].style.border = "30px solid " + colors[2];
  59.       setTimeout(() => {
  60.         x[2].style.border = "30px solid";
  61.         x[1].style.border = "30px solid " + colors[1];
  62.         setTimeout(() => {
  63.           x[1].style.border = "30px solid";
  64.           x[0].style.border = "30px solid " + colors[0];
  65.           setTimeout(() => {
  66.             x[0].style.border = "30px solid";
  67.             traffic()
  68.           }, 3000);
  69.         }, 3000);
  70.       }, 3000);
  71.     }, 3000);
  72.   </script>
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement