Light Switch - Exercise
How do I make an light switch - exercise?
Repurposed and ReJS'd from from Thomas Kimura's Pen Toggle Buttons.. What is a light switch - exercise? How do you make a light switch - exercise? This script and codes were developed by Matthew Nahmias on 27 December 2022, Tuesday.
Light Switch - Exercise - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Light Switch - Exercise</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="wrapper"> <h1 id="title" class="title">Light Switch Exercise</h1> <div id="toggle" class="toggle"> <input type="checkbox" class="check"> <div id="lightSwitch" class="switch lightSwitch"></div> <div class="track lightTrack"></div> </div>
</div> <script src="js/index.js"></script>
</body>
</html>
Light Switch - Exercise - Script Codes CSS Codes
body{ position:absolute; height:100%; width:100%; margin:0px; font-size:16px; line-height:1.5em; font-family: Franklin Gothic Medium, Franklin Gothic, ITC Franklin Gothic, Arial, sans-serif; text-align: center; transition: all .5s cubic-bezier(.95, .25, .30, .65);
}
.off{ background-color: #000;
}
.wrapper{ position:relative; height:50%; width:100%;
}
.title{ font-weight:300; color: #000;
}
.dark{ background-color:yellow;
}
.lightSwitch{ background:#fff;
}
.lightTrack{ background:#cecece;
}
.toggle{ position:absolute; width:100px; height:50px; top:50%; left:0; right:0; margin:0 auto; text-align:center; z-index:1; border-radius:100px;
}
.check{ height:100%; width:100%; border-radius:50%; cursor:pointer; opacity:0; margin:0px; z-index:2;
}
.switch{ position:absolute; top:5px; left:5px; height:40px; width:40px; border-radius:40px; z-index:-1; transition: all 0.5s cubic-bezier(.95, .25, .30, .65);
}
.track{ position:absolute; top:0px; left:0px; width:100%; height:100%; border-radius:50px; z-index:-2; transition: all 0.5s cubic-bezier(.95, .25, .30, .65);
}
.light{ position:absolute; top:-30px; left:0; right:0; margin:0 auto; width:10px; height:10px; border-radius:10px; transition: all 0.5s cubic-bezier(.95, .25, .30, .65);
}
.move{ transform: translate(50px); background:#2ecc71;
}
.move + .track{ background:#fff;
}
Light Switch - Exercise - Script Codes JS Codes
// Store the toggle and lightswitch elements in variables
var toggle = document.getElementById('toggle');
var lightSwitch = document.getElementById('lightSwitch');
var title = document.getElementById('title');
// Toggle the off class on the body and the move class on the lightswitch
function backgroundToggle(){ document.body.classList.toggle('off'); lightSwitch.classList.toggle('move'); title.classList.toggle('dark');
}
// Create an event listener that watches for a click on the toggle element and runs the backgroundToggle function
toggle.onclick = backgroundToggle;
Developer | Matthew Nahmias |
Username | mnahmias |
Uploaded | December 27, 2022 |
Rating | 3 |
Size | 2,365 Kb |
Views | 12,144 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
React Random Color Generator | 2,910 Kb |
Madlib Game - Solution | 2,258 Kb |
Light Switch - Solution | 2,333 Kb |
Click Event - Exercise | 1,953 Kb |
Click Event - Solution | 1,956 Kb |
A Pen by Matthew Nahmias | 4,649 Kb |
Hover Cards | 4,545 Kb |
Space Pen | 5,202 Kb |
Bus Animation | 5,854 Kb |
Travel Preloader | 4,014 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
A Different Type of Gallery | DonPage | 2,950 Kb |
My Interests | Anshusaxenaarora | 2,015 Kb |
Banner Ad | Raquellorenzana | 4,172 Kb |
A Pen by Gregory Potdevin | GregoryPotdevin | 1,713 Kb |
CSS Flip Animation | Bbodine1 | 2,525 Kb |
Animated Donut Chart | Jplhomer | 3,808 Kb |
Vue Transition | Chenming142 | 4,561 Kb |
Pattern lab logo | TimPietrusky | 3,666 Kb |
Reading Grid | Tappily | 4,306 Kb |
IPhone5S SVG Space Grey | Onlinechris | 75,035 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!