esp8266/webserver/index.html

135 lines
3.3 KiB
HTML
Raw Normal View History

2024-03-25 02:29:53 +00:00
<!DOCTYPE html>
<html>
<head>
<script>
const action = (url) => {
fetch("http://192.168.0.31/" + url, { method: "post" })
.then((response) => console.log(response))
.catch((err) => console.error(err));
}
window.onload = (event) => {
document.querySelector("input.switch1").onclick = (e) => action(e.currentTarget.checked ? "switch1on" : "switch1off");
document.querySelector("input.switch2").onclick = (e) => action(e.currentTarget.checked ? "switch2on" : "switch2off");
}
</script>
<style>
* {
margin: 0;
}
body {
background-color: #f1f1f1;
}
.container {
width: calc(100% - 20px);
max-width: 600px;
margin: 0 auto;
padding: 30px 25px;
box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.1);
min-height: 100vh;
background-color: #f5f5f5;
}
h1 {
margin-bottom: 30px;
}
.switch-wrap {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 30px;
}
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
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(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
</head>
<body>
<div class="container">
<section>
<h1>Switches</h1>
<div class="switch-wrap">
<label>Switch1</label>
<label class="switch">
<input type="checkbox" class="switch1" />
<span class="slider round"></span>
</label>
</div>
<div class="switch-wrap">
<label>Switch2</label>
<label class="switch">
<input type="checkbox" class="switch2" />
<span class="slider round"></span>
</label>
</section>
</div>
</div>
</body>
</html>