example 1: Color shifting, −/+ buttons and arrow keys (Ctrl)
example 2: Smart snapping, with optional marks
example 3: Result only, drag disabled, dynamic. %
example 4: Vertical (only modern browsers)
sGlide()
to an empty <div>
with a unique identifier. You can leverage this identifier (or class
) to style the shell and its components with CSS. Hint: use .slider_knob
and .follow_bar
■const callback = o => { var pct = Math.round(o.percent)+'%'; $('#percentage').html(pct); }; $('#myslider_1').sGlide({ height : 10, image : 'images/knob.png', startAt : 70, colorShift : ['#3a4d31', '#7bb560'], buttons : true, drag : callback, onButton : callback });
$('#myslider_2').on('sGlide.ready', function(e, data){ $(this).sGlide('startAt', 66.66); $('#container').css('visibility', 'visible'); }).sGlide({ startAt : 38, pill : false, width : 60, snap : { points : 4, markers : true } });
$('#myslider_3').sGlide({ startAt : 50, height : 20, disabled: true, noHandle: true }); // dynamically update $('#myslider_3').sGlide( 'startAt', input_value, // Number, percent true // animate );
$('#myslider_4').sGlide({ startAt : 33.33, width : 300, unit : 'px', snap : { points : 5, markers : true, type : 'soft' }, vertical: true, noHandle: true });
startAt
prop of an existing slider: slider_div.sGlide('startAt', 68.2)
. To enable animation ($), set the third parameter.slider_div.sGlide('destroy')
($) or sGlide_inst.destroy()
.data-keys="true"
.data-keys="shift"
data-keys="ctrl"
var el = document.getElementById('myslider_4');
var my_slider = new sGlide(el, {
startAt : 33.33,
width : 300,
unit : 'px',
snap : {
points : 5,
markers : true,
type : 'soft'
},
vertical: true,
noHandle: true
}).load(function(data){
this.startAt(data.percent * 2); // 66.66
});
// multiple sliders
var sGlideInstances = [];
var nodes = document.getElementsByClassName('slider_bar');
for (el of nodes){
sGlideInstances.push(new sGlide(el, {
width : 300,
unit : 'px',
buttons : true,
drop : o => {
var pct = Math.round(o.percent)+'%';
document.getElementById('percentage')
.innerHTML = pct;
},
}));
}
Property | Default | Description |
startAt | 0 | Number. Percentage value to set the slider handle position on its creation. Currently only accepts percentage values, but callbacks return both percentage and custom unit values at runtime. |
image | '' | String. Path of handle/knob image to use; e.g. 'images/slider-knob.png' |
retina | false | Boolean. As of version 2. If true, looks for an image with the suffix @2x based on the image property. Make sure the @2x image exists. |
width | 100 | Number. The width of the main shell of the slider. If unit is set to '%' or unset, width will be relative to its parent. |
height | 40 | Number. Pixel value of the height of the main shell of the slider. Ignores unit . |
unit | '%' | String. Also accepts 'px' to govern widths. |
pill | true | Boolean. Set to false to turn off rounded corners. |
disabled | false | Boolean. Disables user interactivity. As of v3, no longer hides knob. Use noHandle . |
colorShift | [ ] | Array. As of version 2. An array of two CSS color values. The first being the start value, the last being the end value. Replaces colorStart and colorEnd . |
vertical | false | Boolean. Rotates the slider 90 degrees counterclockwise using CSS3. The −/+ buttons are exempt, so you'll have to position the slider and the buttons separately. When true, refrain from positioning the slider and its parent elements absolutely or relatively as this will offset the cursor registration. |
totalRange | [0, 0] | Array of two numbers. Custom units indicating start and end slider values. Slider position returned in output.custom |
| true | |
noHandle | false | Boolean. Collapses the knob. As of v3. |
buttons | false | Boolean. Draws −/+ buttons that flank the slider. You can change the HTML content of the buttons — on ready/load — once they've been drawn. Style them as necessary. Clicking one of the buttons will advance the slider 10%. Click & hold to advance continuously. When hard or soft snapping is used, the slider will advance to the snap points. The [enabled] keyboard controls work in the same fashion. |
snap | {…} | Object. Contains the following snap settings. |
snap.points | 0 | Number. Set the number of snap points between 1 and 11. Effectively enables snapping. |
snap.marks | false | Boolean. Draws tiny snap marks to indicate the snap points. |
snap.type | false | String. As of version 2.1. Set to 'hard' so that the slider handle cannot be positioned between snap points. Set to 'soft', like 'hard', but handle is positioned only after it has been dropped. |
snap.sensitivity | 2 | Number. As of version 2.2. Accepts decimal values between 1 & 3 inclusive. The higher the number, the bigger the jump to a snap point. Doesn't apply to hard snap. |
drop | Callback. Fire an event on handle drop. Returns an object containing slider data. | |
drag | Callback. Fire an event on handle drag. Returns an object containing slider data. | |
onSnap | Callback. Fire an event on handle snap. Returns an object containing slider data. | |
onButton | Callback. Fire an event clicking or holding one of the −/+ buttons. Returns an object containing slider data. Requires buttons . | |
| load method in standalone and the sGlide.ready event in jQuery.
|
3.1.0 | retina setting default set to false | 15.02.2018 |
3.0.0 | chainable ($) • added jQuery 3 support ($) • added resize support • removed orientation-change event • removed showKnob to favour newly added noHandle • removed onload callback to favour ready event ($) or load method (standalone) • restored 'custom' property to output on ready • added Ctrl key option • added 2 more snap points (up to 11) • rebuilt snap marks • more accurate snapping • other minor snap improvements & bug fixes • removed CustomEvent polyfill • all callbacks now receive sGlide context (this ) • removed internal custom element getter to favour querySelectorAll • better 'css' & 'extend' functions • improved vertical positioning and alignments; unit default set to null • refactoring and general bug fixes | 10.01.2018 |
2.2.0 | added snap sensitivity (see Breakdown: snap.sensitivity ) • other generic improvements | 17.04.2017 |
2.1.2 | bug fix: text inputs were not selectable by mouse-drag in Chrome for jQuery — a proper if statement in the document's mousemove event listener solved it, thereby possibly increasing performance (applied to both jQuery and standalone) | 01.02.2015 |
2.1.1 | bug fix: just clicking anywhere on bar didn't update value • nor did it update color in follow bar, for which a couple of constraint issues were also fixed | 24.01.2015 |
2.1.0 | removed snap properties hard & onlyOnDrop in favour of snap.type •
also snap.markers became snap.marks •
added totalRange property & runtime values thereof returned •
destroy method now chainable for jQuery •
fixed minor scoping issue •
modified colorShift handling •
significant changes with regards to data entered and data received •
replaced setInterval with event listener (+ IE polyfill) •
removed drag and drop callbacks from initiator function •
added slider data to onload callback •
jQuery: removed unnecessary removeEventListeners for IE that caused an error on destroy | 16.11.2014 |
2.0.0 | new standalone (jquery independent) plugin • major improvements in code structure, stability, accuracy • changed color shift property (see usage) • only corresponding arrow keys for horizontal or vertical • added Windows Phone support • added retina image handling • fixed issues in destroy methods • added shift + arrow keys • and various bug fixes, namely functional inconsistencies | 30.10.2014 |
1.10.0 | added keyboard functionality | 03.01.2014 |
1.9.1 | bug fix: when button is pressed but released off button, button action now gets cleared | 19.12.2013 |
1.9.0 | added −/+ buttons option, along with the onButton and onload callbacks • minor bug fixes | 18.12.2013 |
1.8.8 | stability (some distortion resistance) • better rebuild on mobile • mobile orientation change support | 09.12.2013 |
1.8.7 | snap marks now align to snap points • bug fix: vertical now rebuilds properly | 03.12.2013 |
1.8.5 | added mobile support & the onSnap callback | 02.12.2013 |
1.7.1 | added real snapping and reworked its options • added destroy method — now allows clean rebuild •bug fix: when shell is thinner than knob, knob now retains its position in vertical mode | 28.11.2013 |
1.5.0 | added loadbar capability and "animated" option | 27.11.2013 |
1.0.0 | added Vertical mode • added option to hide knob | 26.11.2013 |
0.3.1 | more accurate snap markers • added color shifting | 25.07.2013 |
0.2.6 | bug fix: constraints when dragging | 20.12.2012 |
0.2.5 | bug fix: when knob is image, startAt now gets the correct knob width | 13.12.2012 |
0.2.0 | added disabled state | 08.12.2012 |
0.1.0 | born | 24.11.2012 |