Skip to content

Commit fffe469

Browse files
committed
Update README.md
1 parent 8143dd3 commit fffe469

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,3 +2735,86 @@ While there are 35 aria properties and states the W3C defines and which you can
27352735
<div align="right">
27362736
<b><a href="#table-of-contents">↥ back to top</a></b>
27372737
</div>
2738+
2739+
## Q. Create a traffic signal light in html?
2740+
2741+
```html
2742+
<!DOCTYPE html>
2743+
<html lang="en">
2744+
<head>
2745+
<meta charset="UTF-8">
2746+
<title>Traffic Signal
2747+
</title>
2748+
<style>
2749+
#green{
2750+
background-color: green;
2751+
width: 100px;
2752+
height: 100px;
2753+
border-radius: 50%;
2754+
border: 2px solid #333;
2755+
}
2756+
#yellow{
2757+
background-color: yellow;
2758+
width: 100px;
2759+
height: 100px;
2760+
border-radius: 50%;
2761+
border: 2px solid #333;
2762+
}
2763+
#red{
2764+
background-color: red;
2765+
width: 100px;
2766+
height: 100px;
2767+
border-radius: 50%;
2768+
border: 2px solid #333;
2769+
}
2770+
</style>
2771+
</head>
2772+
<body onload="timer;">
2773+
<div id="red"></div>
2774+
<div id="yellow"></div>
2775+
<div id="green"></div>
2776+
2777+
<script>
2778+
function startTrafficSignal() {
2779+
2780+
const red = document.getElementById("red");
2781+
const yellow = document.getElementById("yellow");
2782+
const green = document.getElementById("green");
2783+
2784+
green.style.opacity = 1;
2785+
2786+
// Red Signal
2787+
setTimeout(function () {
2788+
green.style.opacity = 0.3;
2789+
red.style.opacity = 1;
2790+
yellow.style.opacity = 0.3;
2791+
}, 7000);
2792+
2793+
// yellow Signal
2794+
setTimeout(function () {
2795+
green.style.opacity = 1;
2796+
red.style.opacity = 0.3;
2797+
yellow.style.opacity = 0.3;
2798+
}, 5000);
2799+
2800+
// Green Signal
2801+
setTimeout(function () {
2802+
green.style.opacity = 0.3;
2803+
red.style.opacity = 0.3;
2804+
yellow.style.opacity = 1;
2805+
}, 12000);
2806+
}
2807+
2808+
const timer = setInterval(function () {
2809+
startTrafficSignal();
2810+
}, 12000);
2811+
2812+
startTrafficSignal();
2813+
</script>
2814+
</body>
2815+
</html>
2816+
```
2817+
2818+
<div align="right">
2819+
<b><a href="#table-of-contents">↥ back to top</a></b>
2820+
</div>

0 commit comments

Comments
 (0)