In this tutorial, we will learn how to create an IOS 7 style toggle switch button using switchery JS.
Switchery is a component that help to create beautiful iOS 7 style switches for checkbox. In the below example we will use CDN of Switchery Plugin but you can download on local.
CDN
https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.min.css
https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.min.js
Example
<!DOCTYPE html>
<html>
<head>
<title>iOS 7 Style Toggle Switch Button Using Switchery.js</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.min.js" type="text/javascript"></script>
</head>
<body>
<input type="checkbox" class="js-switch" checked />
<script type="text/javascript">
var elem = document.querySelector('.js-switch');
var init = new Switchery(elem);
</script>
</body>
</html>
Output
Conclusion
Using Switchery.js makes it easy to create iOS 7-style toggle switches and improve the look of your web app.
Leave a comment