Features
- Full Responsive.
- Scales with its container.
- String and Interger type value support
- Supports touch-devices (iPhone, iPad, Nexus, etc.).
- Fully customisable
Demo/Examples
JsFiddle Examples
Getting Started
Set up your HTML markup.
Move the dist/jq-button-range-slider folder into your project
Add dist/jq-button-range-slider.css in your <head>
<///>
or copy and paste the css from dist/jq-button-range-slider.css
in your main file
Add jq-button-range-slider.js before your closing tag, after jQuery (requires jQuery 1.7 +)
Initialize your slider in your script file or an inline script tag
//Initialize when document is ready;
NOTE: I highly recommend putting your initialization script in an external JS file.
Settings
sliderOptions
Type: array
Default: []
Array of objects with name
and value
per slider option/button
Example:
name: "WHITE" value: "#FFFFFF" name: "BLACK" value: "#000000" name: "RED" value: "#FF0000" name: "YELLOW" value: "#FFFF00" name: "GREEN" value: "#008000" name: "BLUE" value: "#0000FF"
template
Type: string
Default:
<% for (var i = 0; i < sliderOptions.length; i++) { %>
<button type="button" class="yo-btn yo-range-btn" value="<%=sliderOptions[i].value%>">
<%=sliderOptions[i].name%>
</button>
<% } %>
JavaScript micro template for rendering button html
More on JavaScript Micro-Templating
className
Type: string
Default: yo-button-range-slider
html class for slider
Events
Use them as shown below:
var $slider = ;// On change event$slider;
init
Arguments: slider
Fires after first initialization.
afterChange
Arguments: event, range, ui, slider
Fires after slider change
values
Array of selected values
"#0000FF" "#FFFFFF"
ui
hash will look like -
lb: index: 2 //index of button at lower bound value: "#FF0000" ub: index: 5 //index of button at upper bound value: "#000000" ;
reset
Arguments: event, slider
Fires after slider reset to intial values.
destroy
Arguments: event, slider
When slider is destroyed.
Methods
Methods are called on JqButtonRangeSlider instances through the jqButtonRangeSlider method itself.
var $slider = ; // Reset slider$slider; //Set new range$slider;
destroy
Arguments: none
Destroy current slider
setRange
Arguments: ui
Set new range. ui
will be like below with new range
"lb": "#FF0000" "ub": "#FFFF00"
reset
Arguments: none
Reset current slider