diff --git a/Documentation.md b/Documentation.md new file mode 100644 index 0000000..0fcf58b --- /dev/null +++ b/Documentation.md @@ -0,0 +1,141 @@ +jQuery Simple Slider +==================== + +Overview +-------- + +Simple Slider is a jQuery plugin which allows your users to select a value from a numerical range by simply dragging a slider. + +Features +-------- + +* Configurable without editing any JavaScript +* No external dependencies, apart from jQuery +* Compact size +* Unobtrusive JavaScript, activate using data-slider="true" on any input +* Easy to skin/style purely in css, no images required +* Slider value goes directly into your input element, for easy use in normal html forms +* Supports both pre-defined values and a continous ranges +* Supports smooth sliding and snap-to-value sliding +* Supports highlighting the slider background when dragging + +Installation +------------ + +Include jQuery and the Simple Slider JavaScript and CSS files on your page, then activate Simple Slider on your text input using the data-slider attribute: + + + + + + + + + + + +You can also manually turn any text input into a Simple Slider in JavaScript as follows (settings will be taken from data-slider-* attributes): + + $("#my-input").simpleSlider(); + +Attributes can also be specified in the javascript: + + $("#my-input").simpleSlider({ + animate: true, + theme: 'volume', + showScale: true + }); + +Configuration +------------- + +### data-slider-range +> Javascript: range +> +> The range representing the start and end of the slider. Eg. data-slider-range="10,1000" + +### data-slider-step +> Javascript: step +> +> The interval to move when dragging the slider. Eg. data-slider-step="100" + +### data-slider-snap +> Javascript: snap +> +> Setting this to true makes the slider snap to each step when dragging, otherwise dragging will be continuous. Eg. data-slider-snap="true" + +### data-slider-values +> Javascript: allowedValues (array) +> +> A pre-defined list of values to allow sliding for. Eg. data-slider-values="0,100,500,800,2000" + +### data-slider-equal-steps +> Javascript: equalSteps +> +> Setting this to true makes the spacing between each always value equal when used with data-slider-values. Eg. data-slider-equal-steps="true" + +### data-slider-theme +> Javascript: theme +> +> The CSS theme to use when rendering this slider. Setting this value adds a suffix to the CSS class of the slider. Eg. data-slider-theme="volume" + +### data-slider-highlight +> Javascript: highlight +> +> Boolean for if we should highlight the background of the slider as it it dragged. Eg. data-slider-highlight="true" + +### data-slider-showscale +> Javascript: showScale +> +> Boolean for if we should display the minimum and maximum scale below the slider. Eg. data-slider-highlight="true" + +Events +------ + +You can bind to the following jQuery events using bind, for example: $("#my-input").bind("slider:ready", function (event, data) { ... }) + +### slider:ready +> Fired when the slider is loaded and attached to your input field. + +### slider:changed +> Fired when the value of your slider changes. + +All Simple Slider events pass 2 parameters into your function, event and data. event is a regular jQuery event object. data contains the following properties: + +### value +> The current value of the slider. + +### ratio +> How far, as a percentage, the slider is from start to end (0 - 1). + +### el +> The generated outer HTML element representing the slider. + +Getting Slider Values +--------------------- + +The value the user selects with the slider is immediately available inside the value attribute of the text input you attached the slider to. This means you can include Simple Slider in your HTML forms and the the selected value will automatically be send to your server when the form is submitted. + +If you would like to get the slider’s value using javascript, you can register for the slider:changed event: + + $("#my-input").bind("slider:changed", function (event, data) { + // The currently selected value of the slider + alert(data.value); + + // The value as a ratio of the slider (between 0 and 1) + alert(data.ratio); + }); + +Methods +------- + +### selector.simpleSlider("setValue", value); +> Sets the value of the slider. + +### selector.simpleSlider("setRatio", ratio); +> Sets the ratio (see above) of the slider. + +License +------- + +Simple Slider is released under the MIT license. diff --git a/css/simple-slider-volume.css b/css/simple-slider-volume.css index d8a876b..5c350cb 100644 --- a/css/simple-slider-volume.css +++ b/css/simple-slider-volume.css @@ -46,3 +46,21 @@ background: -webkit-linear-gradient(top, #c5c5c5, #a2a2a2); background: linear-gradient(top, #c5c5c5, #a2a2a2); } + +.slider-volume > .scale { + width: 100%; + color: #888; + font-size: small; +} + +.slider-volume > .scale > .min-scale { + float: left; + font-weight: bold; + color: #622; +} + +.slider-volume > .scale > .max-scale { + float: right; + font-weight: bold; + color: #262; +} diff --git a/css/simple-slider.css b/css/simple-slider.css index ca9bf6b..8fee4ce 100644 --- a/css/simple-slider.css +++ b/css/simple-slider.css @@ -53,3 +53,16 @@ border-color: #496805; } +.slider > .scale { + width: 100%; + color: #888; + font-size: small; +} + +.slider > .scale > .min-scale { + float: left; +} + +.slider > .scale > .max-scale { + float: right; +} diff --git a/css/simple-slider.min.css b/css/simple-slider.min.css new file mode 100644 index 0000000..8d815c1 --- /dev/null +++ b/css/simple-slider.min.css @@ -0,0 +1 @@ +.slider{width:300px}.slider>.dragger{background:#8dca09;background:-webkit-linear-gradient(top,#8dca09,#72a307);background:-moz-linear-gradient(top,#8dca09,#72a307);background:linear-gradient(top,#8dca09,#72a307);-webkit-box-shadow:inset 0 2px 2px rgba(255,255,255,0.5),0 2px 8px rgba(0,0,0,0.2);-moz-box-shadow:inset 0 2px 2px rgba(255,255,255,0.5),0 2px 8px rgba(0,0,0,0.2);box-shadow:inset 0 2px 2px rgba(255,255,255,0.5),0 2px 8px rgba(0,0,0,0.2);-webkit-border-radius:10px;-moz-border-radius:10px;border-radius:10px;border:1px solid #496805;width:16px;height:16px}.slider>.dragger:hover{background:-webkit-linear-gradient(top,#8dca09,#8dca09)}.slider>.track,.slider>.highlight-track{background:#ccc;background:-webkit-linear-gradient(top,#bbb,#ddd);background:-moz-linear-gradient(top,#bbb,#ddd);background:linear-gradient(top,#bbb,#ddd);-webkit-box-shadow:inset 0 2px 4px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 2px 4px rgba(0,0,0,0.1);box-shadow:inset 0 2px 4px rgba(0,0,0,0.1);-webkit-border-radius:8px;-moz-border-radius:8px;border-radius:8px;border:1px solid #aaa;height:4px}.slider>.highlight-track{background-color:#8dca09;background:-webkit-linear-gradient(top,#8dca09,#72a307);background:-moz-linear-gradient(top,#8dca09,#72a307);background:linear-gradient(top,#8dca09,#72a307);border-color:#496805}.slider>.scale{width:100%;color:#888;font-size:small}.slider>.scale>.min-scale{float:left}.slider>.scale>.max-scale{float:right} \ No newline at end of file diff --git a/demo.html b/demo.html index ad3b4b0..000c8c5 100644 --- a/demo.html +++ b/demo.html @@ -29,9 +29,15 @@