<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Light Flicker</title>
<style>
/* Basic styling for the light */
#light {
width: 100px;
height: 100px;
background-color: green;
border-radius: 50%;
animation: flicker 0.5s infinite alternate; /* Animation to flicker the light */
}
/* Keyframes for flicker animation */
@keyframes flicker {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
</style>
</head>
<body>
<!-- Light element -->
<div id="light"></div>
<script>
// Function to toggle light color between red and green
function toggleLightColor() {
var light = document.getElementById('light');
if (light.style.backgroundColor === 'green') {
light.style.backgroundColor = 'red';
} else {
light.style.backgroundColor = 'green';
}
}
// Set interval to toggle light color every 2 seconds (2000 milliseconds)
setInterval(toggleLightColor, 2000);
</script>
</body>
</html>