Dark Mode Toggle
Example: The dark mode toggle in setting on Twitter or Facebook
<div class="showcontent">
<!-- <h4 style="line-height: 1.4;"></h4> -->
<div class="container">
<div class="calculator">
<h2>JavaScript<br><span> Age Calculator</span></h2>
<div class="input-box">
<input type="date" id="date">
<button onclick="calculateAge()">Calculator</button>
</div>
<p id="result"></p>
</div>
</div>
</div>
.col-75 .showcontent{
font-family:'Poppins',sans-serif;
padding: 0;
margin: 0;
}
.container{
width: 100%;
height: auto;
background:linear-gradient(135deg, #4203a9,#90bafc);
color: white;
padding: 10px;
}
.calculator h2{
font-size: 30px;
}
.calculator h2 span{
color:#ffff76;
}
.input-box{
margin: 40px 0;
padding: 30px;
background-color: rgba(255, 255, 255, 0.3);
display: flex;
align-items: center;
border-radius: 10px;
}
.input-box input{
flex: 1;
font-size: 18px ;
border: 0;
padding: 14px 20px;
border-radius: 5px;
outline: 0;
margin-right: 10px;
position: relative;
}
.input-box button{
background-color: #ffff76;
border: 0;
outline: 0;
padding: 15px 30px;
color: #333;
border-radius: 5px;
cursor: pointer;
}
.input-box input::-webkit-calendar-picker-indicator{
top: 0;
left: 0;
right: 0;
bottom: 0;
position: absolute;
cursor: pointer;
width: auto;
height: auto;
background-size: 30px;
background-position: calc(100% - 10px);
}
#result{
font-size: 20px;
}
#result span{
color:yellow;
}
let userInput=document.getElementById("date");
let result=document.getElementById("result");
// console.log(new Date().toISOString().split("T")[0]);
userInput.max=new Date().toISOString().split("T")[0];
function calculateAge(){
let birthday=new Date(userInput.value);
//console.log(birthday);
let d1=birthday.getDate();
let m1=birthday.getMonth();
let y1=birthday.getFullYear();
//console.log(m1);
let today=new Date();
let d2=today.getDate();
let m2=today.getMonth();
let y2=today.getFullYear();
let d3,m3,y3;
y3=y2-y1;
m3=m2-m1;
d3=d2-d1;
if(d3< 0){
m3--;
d3+=new Date(y2,m2,0).getDate();
}
if(m3< 0){
y3--;
m3+=12;
}
result.innerHTML=`You are ${y3} years ${m3} months and ${d3} days`;
}
Example: The dark mode toggle in setting on Twitter or Facebook
Example: The Wi-Fi and Bluetooth toggles in the quick setting menu on Android or iOS devices.
Example: In the settings of a messaging app, you might have a toggle switch to enable or disable notifications for new messages.