-
Notifications
You must be signed in to change notification settings - Fork 285
/
index.html
205 lines (150 loc) · 7.42 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>jQuery Nice Select</title>
<link href='https://fonts.googleapis.com/css?family=Work+Sans:300,400,600&Inconsolata:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<div class="header">
<h1>jQuery Nice Select</h1>
<p>A lightweight jQuery plugin that replaces native select elements with customizable dropdowns.</p>
<a href="https://github.com/hernansartorio/jquery-nice-select/archive/v1.1.0.zip" class="button">Download</a>
<a href="https://github.com/hernansartorio/jquery-nice-select" class="button light">View on GitHub</a>
</div>
<h2>Usage</h2>
<p><strong>1.</strong> Include jQuery and the plugin.</p>
<pre><code class="language-html"><script src="path/to/jquery.js"></script>
<script src="path/to/jquery.nice-select.js"></script></code></pre>
<p><strong>2.</strong> Include the plugin styles, either the compiled CSS...</p>
<pre><code class="language-html"><link rel="stylesheet" href="path/to/nice-select.css"></code></pre>
<p>...or, ideally, import the SASS source (if you use SASS) in your main stylesheet for easier customization.</p>
<pre><code class="language-scss">@import 'nice-select'; // Or 'nice-select-prefixed'. See 'Notes' section.</code></pre>
<p><strong>3.</strong> Finally, initialize the plugin.</p>
<pre><code class="language-js">$(document).ready(function() {
$('select').niceSelect();
});</code></pre>
<p>All done. That will turn this:</p>
<div class="box">
<select class="ignore">
<option value="1">Some option</option>
<option value="2">Another option</option>
<option value="3" disabled>A disabled option</option>
<option value="4">Potato</option>
</select>
</div>
<p>...into this:</p>
<div class="box">
<select>
<option value="1">Some option</option>
<option value="2">Another option</option>
<option value="3" disabled>A disabled option</option>
<option value="4">Potato</option>
</select>
</div>
<p>There are no settings (a native select doesn't have settings), although there are a couple of special features, documented below.</p>
<h2>Display text</h2>
<p>You can specify an alternate text for each option, which will be displayed on the dropdown when that option is selected.</p>
<p>Add a <code class="language-html">data-display</code> attribute to the desired options. For example:</p>
<pre><code class="language-html"><select>
<option data-display="Select">Nothing</option>
<option value="1">Some option</option>
<option value="2">Another option</option>
<option value="3" disabled>A disabled option</option>
<option value="4">Potato</option>
</select></code></pre>
<div class="box">
<select>
<option data-display="Select">Nothing</option>
<option value="1">Some option</option>
<option value="2">Another option</option>
<option value="3" disabled>A disabled option</option>
<option value="4">Potato</option>
</select>
</div>
<h2>Custom classes</h2>
<p>Every class you assign to a select element will be copied to the generated dropdown. That way you can customize different versions of it to your needs just by adding new CSS.</p>
<p>These are some examples included in the plugin stylesheet:</p>
<div class="box">
<label>Wide</label>
<select class="wide">
<option data-display="Select">Nothing</option>
<option value="1">Some option</option>
<option value="2">Another option</option>
<option value="3" disabled>A disabled option</option>
<option value="4">Potato</option>
</select>
</div>
<div class="box">
<label class="right">Right</label>
<select class="right">
<option data-display="Select">Nothing</option>
<option value="1">Some option</option>
<option value="2">Another option</option>
<option value="3" disabled>A disabled option</option>
<option value="4">Potato</option>
</select>
</div>
<div class="box">
<label>Small</label>
<select class="small">
<option data-display="Select">Nothing</option>
<option value="1">Some option</option>
<option value="2">Another option</option>
<option value="3" disabled>A disabled option</option>
<option value="4">Potato</option>
</select>
</div>
<h2>Methods</h2>
<h3>update</h3>
<p>Updates the custom dropdown to reflect any changes made to the original select element.</p>
<pre><code class="language-js">$('select').niceSelect('update');</code></pre>
<h3>destroy</h3>
<p>Removes the custom dropdown and unbinds all its events.</p>
<pre><code class="language-js">$('select').niceSelect('destroy');</code></pre>
<h2>Notes</h2>
<ul>
<li>
<p>Autoprefixer is used to add vendor prefixes to CSS rules for older browser support. A <i>nice-select-prefixed.scss</i> file is also generated if you wish to include the SASS file in your project and you're not using Autoprefixer.</p>
</li>
<li>
<p>In some cases there can be a brief flash in which the native selects are displayed—between the time the page is loaded and the scripts are run. This can be fixed by adding a CSS rule to hide them beforehand:</p>
<pre><code class="language-scss">select {
display: none;
}</code></pre>
<p>Note that the above rule will hide all native select elements. If you're only applying the plugin to some select elements you should adapt the rule accordingly.</p>
</li>
</ul>
<div class="footer">
<h2>Use responsibly</h2>
<p><a href="http://www.lukew.com/ff/entry.asp?1950">Dropdowns should be the UI of last resort.</a></p>
<a href="https://github.com/hernansartorio/jquery-nice-select/archive/v1.1.0.zip" class="button">Download</a>
<a href="https://github.com/hernansartorio/jquery-nice-select" class="button light">View on GitHub</a>
<div class="credit">
Made by <a href="http://hernansartorio.com?r=ns">Hernán Sartorio</a>
</div>
</div>
</div>
<script src="js/jquery.js"></script>
<script src="js/jquery.nice-select.min.js"></script>
<script src="js/fastclick.js"></script>
<script src="js/prism.js"></script>
<script>
$(document).ready(function() {
$('select:not(.ignore)').niceSelect();
FastClick.attach(document.body);
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-64633646-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>