forked from Tejas1510/Awesome-Javascript-and-React-Project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLight on and off
151 lines (136 loc) · 2.79 KB
/
Light on and off
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap" rel="stylesheet">
<style>
*{ margin: 0; padding:0; font-family: 'Josefin Sans', sans-serif;}
h1{
text-align: center;
margin-top: 40px;
text-transform: uppercase;
}
.lightapp{
width: 100%;
height: 80vh;
display: flex;
justify-content: center;
align-items: center;
}
figcaption{
text-align: center;
}
.onoffbtn{
width: 100%;
margin-top: -50px;
display: flex;
justify-content: center;
align-items: center;
}
.switch {
position: relative;
display: inline-block;
width: 100px;
height: 50px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: brown;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 41px;
width: 40px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(40px);
-ms-transform: translateX(40px);
transform: translateX(40px);
}
</style>
</head>
<body>
<h1 id="bulbdata"> Lights ON OFF </h1>
<br>
<main class="lightapp">
<figure class="lightstyle">
<img src="lightoff.jpg" id="lightid1" >
<figcaption>
<p> Light ON OFF </p>
</figcaption>
</figure>
<figure class="lightstyle">
<img src="lightoff.jpg" id="lightid2">
<figcaption>
<p> Light ON OFF </p>
</figcaption>
</figure>
<figure class="lightstyle">
<img src="lightoff.jpg" id="lightid3">
<figcaption>
<p> Light ON OFF </p>
</figcaption>
</figure>
<figure class="lightstyle">
<img src="lightoff.jpg" id="lightid4">
<figcaption>
<p> Light ON OFF </p>
</figcaption>
</figure>
<figure class="lightstyle">
<img src="lightoff.jpg" id="lightid5">
<figcaption>
<p> Light ON OFF </p>
</figcaption>
</figure>
</main>
<div class="onoffbtn">
<label class="switch">
<input type="checkbox"> <span class="slider"
onclick="tubelight()" > </span>
</label>
</div>
<script>
const tubelight = () =>{
let btext = document.getElementById('bulbdata');
for(x=1; x<6; x++){
let bid =document.getElementById('lightid'.concat(x));
console.log(bid.src);
if(bid.src.match('lighton')){
bid.src="lightoff.jpg";
btext.innerHTML = "Light OFF";
btext.style.color = "black";
}else{
bid.src="lighton.jpg";
btext.innerHTML = "Light ON";
btext.style.color = "red";
}
}
}
</script>
</body>
</html>