Light Switch - Solution

Size
2,333 Kb
Views
10,120

How do I make an light switch - solution?

Repurposed and ReJS'd from from Thomas Kimura's Pen Toggle Buttons.. What is a light switch - solution? How do you make a light switch - solution? This script and codes were developed by Matthew Nahmias on 27 December 2022, Tuesday.

Light Switch - Solution Previews

Light Switch - Solution - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Light Switch - Solution</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="wrapper"> <h1 class="title">Light Switch Solution</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 - Solution - 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;
}
.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 - Solution - Script Codes JS Codes

// Store the toggle and lightswitch elements in variables
var toggle = document.getElementById('toggle');
var lightSwitch = document.getElementById('lightSwitch');
// 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');
}
// Create an event listener that watches for a click on the toggle element and runs the backgroundToggle function
toggle.onclick = backgroundToggle;
Light Switch - Solution - Script Codes
Light Switch - Solution - Script Codes
Home Page Home
Developer Matthew Nahmias
Username mnahmias
Uploaded December 27, 2022
Rating 3
Size 2,333 Kb
Views 10,120
Do you need developer help for Light Switch - Solution?

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!

Matthew Nahmias (mnahmias) Script Codes
Create amazing sales emails with AI!

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!