Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <title>street light</title>
  6. <style>
  7. #traffic {
  8. width: 400px;
  9. height: 800px;
  10. border-radius: 10%;
  11. background-color: gold;
  12. position: absolute;
  13. left: 30%;
  14. opacity: 0.8;
  15.  
  16. }
  17.  
  18. .light {
  19. border-radius: 50%;
  20. border: solid 1px;
  21. width: 230px;
  22. height: 230px;
  23. margin-bottom: 20px;
  24. position: relative;
  25. left: 75px;
  26. z-index:5;
  27.  
  28. }
  29.  
  30. #container {
  31. /* border:solid 3px;
  32. */
  33. position: relative;
  34. top: 2%;
  35. }
  36.  
  37. #first {
  38. background-color: tomato;
  39. }
  40. #second{
  41. background-color:yellow;
  42. }
  43.  
  44. #third{
  45. background-color:green;
  46. }
  47.  
  48. .flash{
  49. animation-name:tomato-red;
  50. animation-duration:0.4s;
  51. animation-iteration-count:infinite;
  52. }
  53.  
  54. @keyframes tomato-red{
  55. from {background-color:tomato;}
  56. to {background-color:red;}
  57.  
  58. }
  59. </style>
  60. </head>
  61.  
  62. <body>
  63. <div id="traffic">
  64. <div id="container">
  65. <div class="light" id="first"></div>
  66. <div class="light" id="second"></div>
  67. <div class="light" id="third"></div>
  68. </div>
  69. </div>
  70. <script type="text/javascript">
  71. var red = document.getElementById("first");
  72.  
  73.  
  74. // below we are adding an event listener to the element with the id of "first" so that when we click on the div, we add a class called "flash" and that class has an animation that changes the color back and forth between tomato and red. There are so many other ways we could do this. We could instead of adding an event listener, actually go into the style of the div with the id of "first" and changed the background color from red to tomato and go back and forth.//
  75.  
  76. // Julia this is a really tricky quesiton but since our event listener is with click, how could we possibly un-add the "flash" class when we click another time. It's tricky because in this case, everything is happening with the event of a "click". It's totally do-able...just a bit tricky:)
  77.  
  78. red.addEventListener("click", function() {
  79. // console.log(red.style);
  80. red.classList.add("flash");
  81.  
  82.  
  83. })
  84. </script>
  85. </body>
  86.  
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement