5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <title>jQuery Mobile Docs - Sliders</title>
7 <link rel="stylesheet" href="../../../css/themes/default/" />
8 <link rel="stylesheet" href="../../_assets/css/jqm-docs.css"/>
9 <script src="../../../js/jquery.js"></script>
10 <script src="../../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
11 <script src="../../_assets/js/jqm-docs.js"></script>
12 <script src="../../../js/"></script>
16 <div data-role="page" class="type-interior">
18 <div data-role="header" data-theme="f">
19 <h1>Flip Toggle Switch</h1>
20 <a href="../../../" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
21 </div><!-- /header -->
23 <div data-role="content">
24 <div class="content-primary">
26 <form action="#" method="get">
27 <h2>Flip toggle switch</h2>
29 <ul data-role="controlgroup" data-type="horizontal" class="localnav">
30 <li><a href="index.html" data-role="button" data-transition="fade" class="ui-btn-active">Basics</a></li>
31 <li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
32 <li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
33 <li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
36 <p>A binary "flip" switch is a common UI element on mobile devices that is used for binary on/off or true/false data input. You can either drag the flip handle like a slider or tap one side of the switch.</p>
38 <p>To create a flip toggle, start with a <code>select</code> with two options. The first option will be styled as the "on" state switch and the second will be styled as the "off" state so write your options accordingly. View the <a href="../../api/data-attributes.html">data- attribute reference</a> to see all the possible attributes you can add to flip switches.</p>
40 <p>Set the <code>for</code> attribute of the <code>label</code> to match the ID of the <code>input</code> so they are semantically associated. It's possible to <a href="../docs-forms.html">accessibly hide the label</a> if it's not desired in the page layout, but we require that it is present in the markup for semantic and accessibility reasons.</p>
43 <label for="flip-a">Select slider:</label>
44 <select name="slider" id="flip-a" data-role="slider">
45 <option value="off">Off</option>
46 <option value="on">On</option>
50 <p>This will produce a basic flip toggle switch input. The default styles set the width of the switch to 100% of the parent container and stacks the label on a separate line.</p>
52 <label for="flip-a">Flip switch:</label>
53 <select name="slider" id="flip-a" data-role="slider">
54 <option value="off">Off</option>
55 <option value="on">On</option>
58 <p>Optionally wrap the switch markup in a container with the <code>data-role="fieldcontain"</code> attribute to help visually group it in a longer form.</p>
61 <strong><div data-role="fieldcontain">
62 </strong><label for="flip-b">Flip switch:</label>
63 <select name="slider" id="flip-b" data-role="slider">
64 <option value="no">No</option>
65 <option value="yes">Yes</option>
68 </strong></code></pre>
69 <p>The flip toggle switch is now displayed like this:</p>
70 <div data-role="fieldcontain">
71 <label for="flip-b">Flip switch:</label>
72 <select name="slider" id="flip-b" data-role="slider">
73 <option value="no">No</option>
74 <option value="yes">Yes</option>
79 <h2>Theming the flip switch</h2>
81 <p>Like all form elements, this widget will automatically inherit the theme from it's parent container. TO choose a specific theme color swatch, specify the <code>data-theme</code> attribute on the select and specify a swatch letter.</p>
84 <div data-role="fieldcontain">
85 <label for="flip-c">Flip switch:</label>
86 <select name="slider" id="flip-c" data-role="slider" data-theme="a">
87 <option value="no">No</option>
88 <option value="yes">Yes</option>
92 <p>This results in a switch with the A swatch colors for the handle. Note that the lefthand "on" state gets the active state color.</p>
93 <div data-role="fieldcontain">
94 <label for="flip-c">Flip switch:</label>
95 <select name="slider" id="flip-c" data-role="slider" data-theme="a">
96 <option value="no">No</option>
97 <option value="yes">Yes</option>
101 <p>Here is a E swatch variation:</p>
102 <div data-role="fieldcontain">
103 <label for="flip-d">Flip switch:</label>
104 <select name="slider" id="flip-d" data-role="slider" data-theme="e">
105 <option value="no">No</option>
106 <option value="yes">Yes</option>
110 <h2>Calling the switch plugin</h2>
112 <p>This plugin will auto initialize on any page that contains a <code>select</code> with the <code>data-role="slider"</code> attribute. However, if needed you can directly call the <code>slider</code> plugin on any selector, just like any jQuery plugin:</p>
114 $('select').slider();
118 </div><!--/content-primary -->
120 <div class="content-secondary">
122 <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
124 <h3>More in this section</h3>
126 <ul data-role="listview" data-theme="c" data-dividertheme="d">
128 <li data-role="list-divider">Form elements</li>
129 <li><a href="../docs-forms.html">Form basics</a></li>
130 <li><a href="../forms-all.html">Form element gallery</a></li>
131 <li><a href="../textinputs/index.html">Text inputs</a></li>
132 <li><a href="../search/">Search input</a></li>
133 <li><a href="../slider/">Slider</a></li>
134 <li data-theme="a"><a href="index.html">Flip toggle switch</a></li>
135 <li><a href="../radiobuttons/">Radio buttons</a></li>
136 <li><a href="../checkboxes/">Checkboxes</a></li>
137 <li><a href="../selects/">Select menus</a></li>
138 <li><a href="../forms-themes.html">Theming forms</a></li>
139 <li><a href="../forms-all-native.html">Native form elements</a></li>
140 <li><a href="../forms-sample.html">Submitting forms</a></li>
147 </div><!-- /content -->
149 <div data-role="footer" class="footer-docs" data-theme="c">
150 <p>© 2011 The jQuery Project</p>