1.0.6 • Published 6 years ago

@creenv/slider v1.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Creenv slider

A simple and fully customizable slider, in native javascript. No need for complexity.

Usage

var Slider = require("@creenv/slider");

var callbackChange = function (val) {
  console.log("value has changed: "+val);
}

var callbackChangeFinished = function (val) {
  console.log("user has finished sliding: "+val);
}

var mySlider = new Slider(0, 100, 0.5, 10, callbackChange, callbackChangeFinished);
document.body.appendChild(mySlider.dom);

Custom the style

The css of the slider will be inserted into the < head > tags, within < style > tags identified by id="creenv-slider-style", right at the beginning. You can overwrite any of these rules to apply you own rules. Only 3 classes are used by @creenv/slider:

ClassWhat ?
.creenv-slider-containerThe container of the whole slider. Its background-color will be the background color of the slider
.creenv-slider-progressThe progress bar. Its width will be programatically set to match the value of the slider
.creenv-slider-cursorThe draggable cursor

Constructor

Slider(min: number, max: number, step: number, value: number, callbackChange: function, callbackChangeFinished: function, vertical: boolean)

ParameterTypeWhat?Default value
minnumberThe left value of the slider0
maxnumberThe right value of the slider100
stepnumberStep between each possible value0.5
valuenumberDefault value the slider can take10
callbackChangefunctionCallback function called when a change is detected to the value. Set it to undefined if you don't want any action()=>{}
callbackChangeFinishedfunctionCallback function called when the user is done sliding. Will only be triggered when mouseclick is released. Set it to undefined if you don't want any action()=>{}
verticalboleanIf set to true, the slider will be vertical. It will need a container which height will be the desired slider's heightfalse

Accessible (read/write) class members

MemberTypeWhat ?
.valuenumberCurrent value of the slider
.minnumberThe left value of the slider
.maxnumberThe right value of the slider
.stepnumberThe step between each possible value
.onChangefunctionCalled when value changes because of user input
.onChangeFinishedfunctionCalled when value change is finished
.domHTMLElementThe dom element representing the entire slider component
.xnumberX Offset of the slider, from the left of the window. If vertical is set to true, Y of the slider
.widthnumberWidth, in px, of the slider. If vertical is set to true, height of the slider
.containerHTMLElementDOM element of the container (=.dom)
.progressHTMLElementDOM element of the progress bar inside the container
.cursorHTMLElementDOM element of the cursor inside the container