官网地址: https://www.runoob.com/try/try.php?filename=ionic_toggle
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>ionic Toggle(开关控件)</title>
<link href="https://cdn.staticfile.org/ionic/1.3.2/css/ionic.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/ionic/1.3.2/js/ionic.bundle.min.js"></script>
</head>
<body>
<div class="bar bar-header">
<div class="h1 title">切换</div>
</div>
<div class="content has-header">
<ul class="list">
<li class="item item-toggle">
HTML5
<label class="toggle toggle-positive">
<input type="checkbox" checked="">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
<li class="item item-toggle">
CSS3
<label class="toggle toggle-calm">
<input type="checkbox" checked="">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
<li class="item item-toggle">
Flashplayer
<label class="toggle toggle-balanced">
<input type="checkbox">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
<li class="item item-toggle">
Java Applets
<label class="toggle toggle-energized">
<input type="checkbox">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
<li class="item item-toggle">
<label class="toggle toggle-assertive">
<input type="checkbox" checked="">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
<li class="item item-toggle">
Silverlight
<label class="toggle toggle-royal">
<input type="checkbox">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
<li class="item item-toggle">
Web Components
<label class="toggle toggle-dark">
<input type="checkbox" checked="">
<div class="track">
<div class="handle"></div>
</div>
</label>
</li>
</ul>
</div>
</body>
</html>
效果图:
改造后的单个开关控件的快速使用:
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link href="https://cdn.staticfile.org/ionic/1.3.2/css/ionic.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/ionic/1.3.2/js/ionic.bundle.min.js"></script>
</head>
<body>
<!--toggle表示该组件是一个开关,toggle-balanced表示颜色设置-->
<label class="toggle toggle-balanced">
<!--input复选框在界面中是被隐藏的,checked属性决定是否被选中-->
<input type="checkbox" checked="">
<div class="track">
<div class="handle"></div>
</div>
</label>
</body>
</html>
上述这个样式虽然很好,但是在与BootStrap一起结合使用时会产生冲突会导致JS事件不被触发,因此个人的建议做法是根据上述样式与事件功能自己写纯原生的CSS样式和JS事件