noUiSlider Documentation
repository·master·Indexed 26 days ago
https://github.com/leongersen/nouisliderA lightweight, high-performance, and dependency-free JavaScript range slider library. It features GPU animations, full responsiveness, multi-touch support, and accessibility via ARIA attributes and keyboard interaction. The library provides a comprehensive API for controlling handle positions, implementing custom formatters, configuring visual pips, and managing slider events.
What's inside noUiSlider
- noUiSlider is a lightweight, dependency-free JavaScript range slider. It is designed to be fast and accessible, featuring GPU animations to prevent reflows, full responsiveness, and multi-touch support for Android, iOS, and Windows devices. It supports all modern browsers and IE > 9.
Run the noUiSlider documentation locally
masterTo view and contribute to the noUiSlider documentation, you can run a local development server using PHP's built-in web server. This requires PHP to be installed on your system.
Prerequisites
- PHP installed: Ensure PHP is available in your system path.
- Directory Naming: The documentation expects the project to be cloned into a lowercase
nouisliderdirectory.
Setup Steps
- Clone the repository:
git clone https://github.com/leongersen/noUiSlider nouislider - Start the documentation server using npm:
npm run docs - Access the documentation at
http://localhost:8080/nouislider/.
Customizing the Port
To run the server on a different port, set the
PORTenvironment variable:PORT=8086 npm run docsAlternative: Manual PHP Server Start
If you prefer not to use the npm shorthand, you can start the server directly from your root directory (e.g.,
C:/Web) using PHP:php -S localhost:8080 nouislider/documentation/_run/router.phpTesting Changes
The documentation uses the files from the
distfolder. To see changes you have made to the main source reflected in the documentation, you must runnpm run buildbefore viewing the docs.npm run docsAccess noUiSlider documentation and examples
masterFor extensive documentation, including detailed configuration options, API references, and practical examples, visit the official documentation website at https://refreshless.com/nouislider/.Initialize a noUiSlider with create()
masterTo create a new slider, use the
createfunction (also exported asinitialize). Pass the target DOM element and an options object. The function returns an API object used to interact with the slider.Note: The target element must be a single valid DOM element and must not have been previously initialized with noUiSlider.
Configure Pips for visual markers
masterPips allow you to display visual markers (ticks) along the slider. You can choose different modes to control how they are distributed:
PipsMode.Range: Spaced according to the range.PipsMode.Steps: Spaced according to the step value.PipsMode.Positions: Placed at specific numeric values.PipsMode.Count: A fixed number of pips.PipsMode.Values: Placed at specific numeric values (similar to Positions).
Configure keyboard support and accessibility
masternoUiSlider supports keyboard interaction and ARIA attributes for accessibility.
keyboardSupport: A boolean that enables or disables keyboard interaction (defaults totrue). When enabled, handles are focusable viatabindex="0"and respond to keyboard events.handleAttributes: An object that allows you to attach custom HTML attributes to specific handles. The keys should be the handle index (0-based).ariaFormat: A formatter used to define thearia-valuetextattribute for screen readers. If not provided, it defaults to the same formatter used for the standardformatoption.
Configure noUiSlider with Options
masterWhen initializing a slider, you provide anOptionsobject. Therangeproperty is required and defines the scale of the slider. Other properties likestart,step,orientation, andconnectallow you to customize behavior and appearance.Configure noUiSlider CSS classes and prefixes
masterYou can customize the CSS classes used by noUiSlider to match your project's styling.
cssPrefix: A string used as a prefix for all generated classes (defaults tonoUi-). Setting this tofalsedisables prefixing.cssClasses: An object allowing you to override specific class names for slider components (e.g.,target,base,handle,origin,connect,tooltip,pips, etc.).
If you provide a
cssPrefix, the library will automatically prepend it to any class names provided in thecssClassesobject.Customize CSS Classes
masterYou can override the default CSS classes used by noUiSlider by providing acssClassesobject in the options. This is useful when integrating with existing CSS frameworks or custom styling.Configure tooltips and value formatting
masterDisplay formatted values via tooltips or standard formatting:
format: A formatter used to convert raw slider values into human-readable strings for display.tooltips: An option to enable tooltips. It can be a boolean (to enable for all handles) or an array/object specifying a formatter for each specific handle.pips: An option to add visual markers (pips) along the slider track. Supports several modes:PipsMode.Range: Uses the slider's range.PipsMode.Steps: Uses defined steps.PipsMode.Count: Divides the range into a specific number of parts.PipsMode.Positions: Uses specific percentage positions.PipsMode.Values: Uses specific slider values.
Configure slider behavior and orientation
masterControl the physical layout and interaction model of the slider using these options:
direction: Sets the text direction (ltrorrtl).orientation: Sets the slider orientation (horizontalorvertical).behaviour: Defines the interaction type (e.g.,tap).connect: An array of booleans (e.g.,[false, true, true]) that determines which segments of the slider track are 'connected' (colored) between handles.animate: A boolean to enable/disable smooth transitions (defaults totrue).animationDuration: The duration of animations in milliseconds (defaults to300).
Use the noUiSlider API
masterTheAPIinterface provides the primary methods for interacting with a noUiSlider instance after initialization. You can use these methods to control handle positions, listen to events, update configuration, and retrieve current values.