Top Related Projects
jQuery only range slider
noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
A library for panning and zooming elements using CSS transforms :mag:
Quick Overview
Bootstrap-slider is a JavaScript plugin that creates a slider control for web applications, compatible with Bootstrap's styling. It provides a customizable and responsive slider component that can be easily integrated into Bootstrap-based projects, offering various options for customization and interaction.
Pros
- Seamless integration with Bootstrap's design and functionality
- Highly customizable with numerous options for appearance and behavior
- Supports both horizontal and vertical orientations
- Responsive design that adapts to different screen sizes
Cons
- Requires jQuery as a dependency, which may not be ideal for modern projects
- Limited built-in accessibility features
- Documentation could be more comprehensive and up-to-date
- Some reported issues with touch device compatibility
Code Examples
Creating a basic slider:
$('#mySlider').slider({
min: 0,
max: 100,
value: 50
});
Setting up a range slider:
$('#rangeSlider').slider({
min: 0,
max: 100,
value: [25, 75],
range: true
});
Creating a vertical slider with custom formatting:
$('#verticalSlider').slider({
min: 0,
max: 100,
value: 50,
orientation: 'vertical',
formatter: function(value) {
return value + '%';
}
});
Getting Started
- Include the necessary files in your HTML:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/11.0.2/css/bootstrap-slider.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/11.0.2/bootstrap-slider.min.js"></script>
- Create an input element for the slider:
<input id="mySlider" type="text" data-slider-min="0" data-slider-max="100" data-slider-step="1" data-slider-value="50"/>
- Initialize the slider in your JavaScript:
$('#mySlider').slider();
- Customize the slider as needed using the available options and methods provided by the plugin.
Competitor Comparisons
jQuery only range slider
Pros of ion.rangeSlider
- More customizable appearance with various skins and themes
- Supports touch devices and responsive design out of the box
- Offers additional features like grid of values and ability to use custom steps
Cons of ion.rangeSlider
- Larger file size due to more features and styling options
- Steeper learning curve for advanced customizations
- May require more setup for basic functionality compared to bootstrap-slider
Code Comparison
bootstrap-slider basic implementation:
<input type="text" data-slider-min="0" data-slider-max="100" data-slider-step="1" data-slider-value="50"/>
<script>
$('input').slider();
</script>
ion.rangeSlider basic implementation:
<input type="text" id="range" value="" />
<script>
$("#range").ionRangeSlider({
min: 0,
max: 100,
from: 50
});
</script>
Both sliders offer similar basic functionality, but ion.rangeSlider provides more options for customization in its initialization. bootstrap-slider relies more on data attributes for configuration, while ion.rangeSlider uses a more extensive JavaScript object for setup.
noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
Pros of noUiSlider
- More customizable appearance and behavior
- Supports a wider range of input types (e.g., non-linear ranges)
- Smaller file size and better performance
Cons of noUiSlider
- Steeper learning curve due to more configuration options
- Less native integration with Bootstrap framework
- May require more setup for basic use cases
Code Comparison
noUiSlider:
var slider = document.getElementById('slider');
noUiSlider.create(slider, {
start: [20, 80],
connect: true,
range: {
'min': 0,
'max': 100
}
});
bootstrap-slider:
var slider = new Slider('#ex2', {
value: [20, 80],
range: true,
tooltip: 'always'
});
Summary
noUiSlider offers more flexibility and customization options, making it suitable for complex slider requirements. It has a smaller footprint and better performance but may require more initial setup.
bootstrap-slider integrates more seamlessly with Bootstrap and has a simpler API, making it easier to implement basic slider functionality quickly. However, it may be less suitable for advanced use cases and has a larger file size.
Choose noUiSlider for highly customized sliders or when performance is crucial. Opt for bootstrap-slider when working within a Bootstrap ecosystem or for simpler slider needs.
A library for panning and zooming elements using CSS transforms :mag:
Pros of Panzoom
- More versatile, supporting pan and zoom functionality for any HTML element
- Lightweight and dependency-free, making it easier to integrate into various projects
- Supports touch devices and gestures out of the box
Cons of Panzoom
- Lacks specific slider functionality, which Bootstrap-slider specializes in
- May require more custom styling and configuration for slider-like behavior
- Less integrated with Bootstrap framework, potentially requiring additional work for consistent styling
Code Comparison
Bootstrap-slider:
$('#ex1').slider({
formatter: function(value) {
return 'Current value: ' + value;
}
});
Panzoom:
const elem = document.getElementById('myElement')
const panzoom = Panzoom(elem, {
maxScale: 5,
step: 0.5
})
elem.addEventListener('wheel', panzoom.zoomWithWheel)
While Bootstrap-slider focuses on creating customizable sliders, Panzoom provides a broader set of pan and zoom functionalities. Bootstrap-slider is more suitable for projects requiring specific slider controls, especially within Bootstrap-based designs. Panzoom, on the other hand, offers greater flexibility for implementing pan and zoom features on various HTML elements, making it a better choice for interactive image viewers or complex UI components that require both panning and zooming capabilities.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
bootstrap-slider
Originally began as a loose "fork" of bootstrap-slider found on http://www.eyecon.ro/ by Stefan Petre.
Over time, this project has diverged sigfinicantly from Stefan Petre's version and is now almost completely different.
Please ensure that you are using this library instead of the Petre version before creating issues in the repository issue tracker!!
Starting with major release 11.0.0, we only support Bootstrap 4!
Installation
Want to use bower? bower install seiyria-bootstrap-slider
Want to use npm? npm install bootstrap-slider
Want to get it from a CDN? https://cdnjs.com/libraries/bootstrap-slider
Basic Setup
Grab the compiled JS/CSS (minified or non-minified versions) from the /dist directory, load them into your web page, and everything should work!
Remember to load the plugin code after loading the Bootstrap CSS and JQuery.
JQuery is optional and the plugin can operate with or without it.
Look below to see an example of how to interact with the non-JQuery interface.
Supported Browsers
We only support modern browsers!!! Basically, anything below IE10 is not compatible with this plugin!
Examples
You can see all of our API examples here.
Using bootstrap-slider (with JQuery)
Using .slider
namespace
Create an input element and call .slider() on it:
// Instantiate a slider
var mySlider = $("input.slider").slider();
// Call a method on the slider
var value = mySlider.slider('getValue');
// For non-getter methods, you can chain together commands
mySlider
.slider('setValue', 5)
.slider('setValue', 7);
Using .bootstrapSlider
namespace
Create an input element and call .bootstrapSlider() on it:
// Instantiate a slider
var mySlider = $("input.slider").bootstrapSlider();
// Call a method on the slider
var value = mySlider.bootstrapSlider('getValue');
// For non-getter methods, you can chain together commands
mySlider
.bootstrapSlider('setValue', 5)
.bootstrapSlider('setValue', 7);
Using bootstrap-slider (via data-provide
-API)
Create an input element with the data-provide="slider"
attribute automatically
turns it into a slider. Options can be supplied via data-slider-
attributes.
<input
type="text"
name="somename"
data-provide="slider"
data-slider-ticks="[1, 2, 3]"
data-slider-ticks-labels='["short", "medium", "long"]'
data-slider-min="1"
data-slider-max="3"
data-slider-step="1"
data-slider-value="3"
data-slider-tooltip="hide"
>
What if there is already a slider plugin bound to the JQuery namespace?
If there is already a JQuery plugin named slider bound to the JQuery namespace, then this plugin will provide an alternative namespace bootstrapSlider and will emit a console warning telling you the slider namespace has already been taken and will encourage you to use the alternate namespace instead. If the slider namespace is available however, the bootstrapSlider namespace will not exist.
// Instantiate a slider
var mySlider = $("input.slider").bootstrapSlider();
// Call a method on the slider
var value = mySlider.bootstrapSlider('getValue');
// For non-getter methods, you can chain together commands
mySlider
.bootstrapSlider('setValue', 5)
.bootstrapSlider('setValue', 7);
Using bootstrap-slider (without JQuery)
Create an input element in the DOM, and then create an instance of Slider, passing it a selector string referencing the input element.
// Instantiate a slider
var mySlider = new Slider("input.slider", {
// initial options object
});
// Call a method on the slider
var value = mySlider.getValue();
// For non-getter methods, you can chain together commands
mySlider
.setValue(5)
.setValue(7);
Using as CommonJS module
bootstrap-slider can be loaded as a CommonJS module via Browserify, Webpack, or some other build tool.
var Slider = require("bootstrap-slider");
var mySlider = new Slider();
How do I exclude the optional JQuery dependency from my build?
Browserify
Note that the JQuery dependency is considered to be optional. For example, to exclude JQuery from being part of your Browserify build, you would call something like the following (assuming main.js
is requiring bootstrap-slider as a dependency):
browserify --im -u jquery main.js > bundle.js
Webpack
To exclude JQuery from your Webpack build, you will have to go into the Webpack config file for your specific project and add something like the following to your resolve.alias
section:
resolve: {
alias: {
"jquery": path.join(__dirname, "./jquery-stub.js")
}
}
Webpack-encore
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// ...
webpack-encore config
...
;
const config = Encore.getWebpackConfig();
config.resolve.alias["jquery"] = path.resolve(__dirname, 'assets/js/jquery-stub.js');
module.exports = config
Then in your project, you will have to create a stub module for jquery that exports a null
value. Whenever require("jquery")
is mentioned in your project, it will load this stubbed module.
// Path: ./jquery-stub.js
module.exports = null;
Other
Please see the documentation for the specific module loader you are using to find out how to exclude dependencies.
Options
Options can be passed either as a data (data-slider-foo) attribute, or as part of an object in the slider call. The only exception here is the formatter argument - that can not be passed as a data- attribute.
Name | Type | Default | Description |
---|---|---|---|
id | string | '' | set the id of the slider element when it's created |
min | float | 0 | minimum possible value |
max | float | 10 | maximum possible value |
step | float | 1 | increment step |
precision | float | number of digits after the decimal of step value | The number of digits shown after the decimal. Defaults to the number of digits after the decimal of step value. |
orientation | string | 'horizontal' | set the orientation. Accepts 'vertical' or 'horizontal' |
value | float, array | 5 | initial value. Use array to have a range slider. |
range | bool | false | make range slider. Optional if initial value is an array. If initial value is scalar, max will be used for second value. |
selection | string | 'before' | selection placement. Accepts: 'before', 'after' or 'none'. In case of a range slider, the selection will be placed between the handles |
tooltip | string | 'show' | whether to show the tooltip on drag, hide the tooltip, or always show the tooltip. Accepts: 'show', 'hide', or 'always' |
tooltip_split | bool | false | if false show one tootip if true show two tooltips one for each handler |
tooltip_position | string | null | Position of tooltip, relative to slider. Accepts 'top'/'bottom' for horizontal sliders and 'left'/'right' for vertically orientated sliders. Default positions are 'top' for horizontal and 'right' for vertical slider. |
handle | string | 'round' | handle shape. Accepts: 'round', 'square', 'triangle' or 'custom' |
reversed | bool | false | whether or not the slider should be reversed |
rtl | string, bool | 'auto' | whether or not the slider should be shown in rtl mode. Accepts true, false, 'auto'. Default 'auto' : use actual direction of HTML (dir='rtl' ) |
enabled | bool | true | whether or not the slider is initially enabled |
formatter | function | returns the plain value | formatter callback. Return the value wanted to be displayed in the tooltip, useful for string values. If a string is returned it will be indicated in an aria-valuetext attribute. |
natural_arrow_keys | bool | false | The natural order is used for the arrow keys. Arrow up select the upper slider value for vertical sliders, arrow right the righter slider value for a horizontal slider - no matter if the slider was reversed or not. By default the arrow keys are oriented by arrow up/right to the higher slider value, arrow down/left to the lower slider value. |
ticks | array | [ ] | Used to define the values of ticks. Tick marks are indicators to denote special values in the range. This option overwrites min and max options. |
ticks_positions | array | [ ] | Defines the positions of the tick values in percentages. The first value should always be 0, the last value should always be 100 percent. |
ticks_labels | array | [ ] | Defines the labels below the tick marks. Accepts HTML input. |
ticks_snap_bounds | float | 0 | Used to define the snap bounds of a tick. Snaps to the tick if value is within these bounds. |
ticks_tooltip | bool | false | Used to allow for a user to hover over a given tick to see it's value. Useful if custom formatter passed in |
scale | string | 'linear' | Set to 'logarithmic' to use a logarithmic scale. Logarithmic scales will be calculated based on the difference between min to max; e.g. (0..10000) (-100..9900) both have a net range of 10001 and will slide in the same net increments. |
focus | bool | false | Focus the appropriate slider handle after a value change. |
labelledby | string, array | null | ARIA labels for the slider handle's, Use array for multiple values in a range slider. |
rangeHighlights | array | [] | Defines a range array that you want to highlight, for example: [{'start':val1, 'end': val2, 'class': 'optionalAdditionalClassName'}]. |
lock_to_ticks | bool | false | Lock the selection to the values defined at ticks array. |
Functions
NOTE: Optional parameters are italicized.
Function | Parameters | Description |
---|---|---|
getValue | --- | Get the current value from the slider |
setValue | newValue, triggerSlideEvent, triggerChangeEvent | Set a new value for the slider. If optional triggerSlideEvent parameter is true, 'slide' events will be triggered. If optional triggerChangeEvent parameter is true, 'change' events will be triggered. This function takes newValue as either a Number , String , Array . If the value is of type String it must be convertable to an integer or it will throw an error. |
getElement | --- | Get the div slider element |
destroy | --- | Properly clean up and remove the slider instance |
disable | --- | Disables the slider and prevents the user from changing the value |
enable | --- | Enables the slider |
toggle | --- | Toggles the slider between enabled and disabled |
isEnabled | --- | Returns true if enabled, false if disabled |
setAttribute | attribute, value | Updates the slider's attributes |
getAttribute | attribute | Get the slider's attributes |
refresh | options | Refreshes the current slider and resets the slider's value to its default value on initial setup. To override this behaviour and instead maintain the slider's current value, pass the optional options parameter with the property useCurrentValue set to true (eg. refresh({ useCurrentValue: true }) . |
on | eventType, callback | When the slider event eventType is triggered, the callback function will be invoked |
off | eventType, callback | Removes the callback function from the slider event eventType |
relayout | --- | Renders the tooltip again, after initialization. Useful in situations when the slider and tooltip are initially hidden. |
Events
Event | Description | Value |
---|---|---|
slide | This event fires when the slider is dragged | The new slider value |
slideStart | This event fires when dragging starts | The new slider value |
slideStop | This event fires when the dragging stops or has been clicked on | The new slider value |
change | This event fires when the slider value has changed | An object with 2 properties: "oldValue" and "newValue" |
slideEnabled | This event fires when the slider is enabled | N/A |
slideDisabled | This event fires when the slider is disabled | N/A |
How Do I Run This Locally?
- Clone the repository
- Run
nvm use
in your Terminal to switch to the proper Node/NPM version - Once you are on specified Node version, run
npm install
- Install the Grunt CLI:
npm install grunt-cli -g
- Type
grunt dev
to launch browser window with Examples page
Grunt Tasks
This plugin uses Grunt as its command-line task runner.
To install the Grunt CLI, type npm install grunt-cli -g
.
To execute any of the commands, type grunt <task-name>
in your terminal instance.
The following is a list of the commonly-used command line tasks:
grunt development
: Generates theindex.html
, compiles the SASS/JS to the/temp
directory, and launches the index.html in your system's default browser. As changes are made to source code, the browser window will auto-refresh.grunt production
: Generates the/dist
directory with minified and unminified assetts.grunt dev
: Alias forgrunt development
grunt prod
: Alias forgrunt production
grunt build
: Transpiles JavaScript source via Babel and compiles LESS source to CSS totemp
directory.grunt lint
: Runs JSLint on the JavaScript source code files, and SASS-Lint on the SASS source code files.grunt test
: Runs unit tests contained in/test
directory via Jasmine 2.x.x
Version Bumping and Publishing (Maintainers Only)
For versioning rules, we follow the Semver convention.
To do the following release tasks:
- bump the version
- publish a new version to NPM
- update the
gh-pages
branch - push a new
dist
bundle to themaster
branch on the remoteorigin
- push new tags to the remote
origin
Type the following command:
npm run release <patch|minor|major>
If you do not specify a version bump type, the script will automatically defer to a patch bump.
Updating Github.io Page
The Github.io page can be automatically updated by running the following command:
npm run update-gh-pages
This command will handle generating the latest versions of the JS/CSS and index.html page, and push them to the gh-pages
branch.
Other Platforms & Libraries
- Ruby on Rails
- knockout.js (@cosminstefanxp, #81)
- AngularJS
- Angular (@moritzvieli)
- EmberJS (@ksnyde)
- ReactJS
- NuGet (@ChrisMissal)
- MeteorJS
- Maven
- Vue.js (@pimlie)
Maintainers
- Kyle Kemp
- Rohit Kalkur
- Twitter: @Rovolutionary
- Github: rovolution
Looking for a Premium UI Kit?
AdminKit is a developer friendly & highly customizable Bootstrap 5 admin template featuring hundreds of UI components, forms, tables, charts and icons. Learn more.
Top Related Projects
jQuery only range slider
noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
A library for panning and zooming elements using CSS transforms :mag:
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot