Sliders are thin tracks with one or more handles on them that the user can drag along the track.
The goal of a slider is to provide an alternative input method for defining a numerical value; the slider represents a range, and sliding a handle along the track defines a value within this range.
Sliders can be in either horizontal or vertical orientation. When horizontal, the left end of the track usually represents the lowest value, while in a vertical orientation, the bottom of the slide is usually the lowest value.
To use script.aculo.us's slider capabilities, you'll need to load the slider.js module along with the prototype.js module. So your minimum loading for script.aculo.us will look like this −
Creating a slider is, as usual, a matter of constructing a custom object over a few existing elements in your page's DOM. You'll need two elements here, one for the handle and one for the track as follows −
new Control.Slider(handle, track [ , options ] );
The track element is usually a <div>, and the handle element is a <div> or <span> within the track element. Both can be passed either by their id= or by direct DOM references, as usual.
You can use one or more of the following options while creating your Slider object.
|Sr.No||Option & Description|
Defines the orientation of the control as horizontal or vertical. The default orientation is horizontal.
Defines the range of the slider values as an instance of a Prototype ObjectRange instance. Defaults to 0 through 1.
Defines the discrete set of values that the slider can acquire. If omitted, all values within the range can be set.
Sets the initial value of the slider. If omitted, the value represented by the leftmost (or top-most) edge of the slider is the initial value.
If true, it creates a slide that is initially disabled. Obviously defaults to false.
Will update the slider's value and thus move the slider handle to the appropriate position.
Will set the slider to the disabled state (disabled = true).
Will set the slider to the enabled state (disabled = false).
You can provide the following callbacks in the options parameter −
|Sr.No||Option & Description|
Called whenever the Slider is moved by dragging. The called function gets the slider value as its parameter.
Called whenever the Slider has finished moving or has had its value changed via the setSlider Value function. The called function gets the slider value as its parameter.
Points to note:
You can change the slider image of any slider using CSS. Use CSS properties background-image: url(track.gif) and background-repeat: no-repeat to set the slider image.
The range value can be specified using $R(minValue, MaxValue). For example, $R(1, 100).
The range value can be specified in terms of specific values. For example values: [1,25,50,75,100]. In this case, the slider would only achieve the discrete values listed as the handle was moved.
At any time, the value of the slider can be set under program control by calling the setValue() method of the slider instance, as in: sliderInstance.setValue(50);
This will produce following result −