jQuery Selectric
jQuery Selectric is a jQuery plugin designed to help at stylizing and manipulating HTML selects.
- Keyboard navigation (Up/Down/Left/Right/Word search)
- Easily customizable
- Pretty lightweight
- Options box always stay visible
- Doesn't rely on external libraries (besides jQuery)
- Word search works with western latin characters set (for example: á, ñ, ç...)
How to use:
Make sure to include jQuery in your page:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
Include jQuery Selectric:
<script src="js/jquery.selectric.min.js"></script>
Include jQuery Selectric styles, and change it to your taste :D (please refer to our demo page for more themes and other customizations)
<link rel="stylesheet" href="selectric.css">
Initialize jQuery Selectric:
<script>
$(function() {
$('select').selectric();
});
</script>
Options:
You can pass an options object as the first parameter when you call the plugin. For example:
$('select').selectric({
maxHeight: 200
});
{
onBeforeInit: function() {},
onInit: function() {},
onBeforeOpen: function() {},
onOpen: function() {},
onBeforeClose: function() {},
onClose: function() {},
onBeforeChange: function() {},
onChange: function(element) {
$(element).change();
},
onRefresh: function() {},
maxHeight: 300,
keySearchTimeout: 500,
arrowButtonMarkup: '<b class="button">&#x25be;</b>',
disableOnMobile: false,
openOnHover: false,
hoverIntentTimeout: 500,
expandToItemText: false,
responsive: false,
customClass: {
prefix: 'selectric',
camelCase: false
},
optionsItemBuilder: '{text}',
labelBuilder: '{text}',
preventWindowScroll: true,
inheritOriginalWidth: false,
stopPropagation: true,
allowWrap: true,
forceRenderAbove: false,
forceRenderBelow: false,
multiple: {
separator: ', ',
keepMenuOpen: true,
maxLabelEntries: false
}
}
Events:
All events are called on original element, first argument is the original element too. And can be bound like this:
$('select').on('eventname', function(element) {
});
eventname
can be one of the following:
Event name | Description |
selectric-before-init | Fired before plugin initialize |
selectric-init | Fired plugin has been fully initialized |
selectric-before-open | Fired before select options opens |
selectric-open | Fired after select options opens |
selectric-before-close | Fired before select options closes |
selectric-close | Fired after select options closes |
selectric-before-highlight | Fired before a select option is highlighted |
selectric-highlight | Fired when a select option is highlighted |
selectric-before-select | Fired before a select option is selected |
selectric-select | Fired before a select option is selected |
selectric-before-change | Fired before select options change |
selectric-change | Fired when select options change |
selectric-refresh | Fired when the Selectric is refreshed |
Public methods:
var Selectric = $('select').data('selectric');
Selectric.open();
Selectric.close();
Selectric.destroy();
Selectric.refresh();
Selectric.init();
$('select').selectric('open');
$('select').selectric('close');
$('select').selectric('destroy');
$('select').selectric('refresh');
$('select').selectric('init');
Browser support:
- Firefox
- Chrome
- Safari
- Internet Explorer 7+
- Opera