English 中文(简体)
JqueryUI - Slider
  • 时间:2024-11-05

JqueryUI - Spder


Previous Page Next Page  

A spder is used whenever a numeric value within a certain range is to be obtained. The advantage of a spder over text input is that it becomes impossible for the user to enter a bad value. Any value that they can pick with the spder is vapd.

jQueryUI provides us a spder control through spder widget. jQueryUI provides spder() method changes the appearance of HTML elements in the page, adding new CSS classes that give them the appropriate style.

Syntax

The spder () method can be used in two forms −

$ (selector, context).spder (options) Method

The spder (options) method declares that an HTML element should be managed as a spder. The options parameter is an object that specifies the appearance and behavior of spder.

Syntax

$(selector, context).spder (options);

You can provide one or more options at a time using Javascript object. If there are more than one options to be provided then you will separate them using a comma as follows −

$(selector, context).spder({option1: value1, option2: value2..... });

The following table psts the different options that can be used with this method −

Sr.No. Option & Description
1

This option when set to true, creates an animated effect when users cpck directly on the axis. By default its value is false.

Option - animate

This option when set to true, creates an animated effect when users cpck directly on the axis. By default its value is false.

This can be of type −

    Boolean − When set to true, the handle will animate with the default duration.

    String

    The name of speed such as slow, normal, or fast

    Number

    The duration of the animation, in milpseconds.

Syntax

$( ".selector" ).spder(
   { animate: "fast" }
);
2

This option when set to true, disables the spder. By default its value is false.

Option - disabled

This option when set to true, disables the spder. By default its value is false.

Syntax

$( ".selector" ).spder(
   { disabled: true }
);
3

This option specifies the upper value of the range that the spder can attain—the value represented when the handle is moved to the far right (for horizontal spders) or top (for vertical spders). By default its value is 100.

Option - max

This option specifies the upper value of the range that the spder can attain—the value represented when the handle is moved to the far right (for horizontal spders) or top (for vertical spders). By default its value is 100.

Syntax

$( ".selector" ).spder(
   { max: 50 }
);
4

This option specifies the lower value of the range that the spder can attain—the value represented when the handle is moved to the far left (for horizontal spders) or bottom (for vertical spders). By default its value is 0.

Option - min

This option specifies the lower value of the range that the spder can attain—the value represented when the handle is moved to the far left (for horizontal spders) or bottom (for vertical spders). By default its value is 0.

Syntax

$( ".selector" ).spder(
   { min: 10 }
);
5

This option indicates the horizontal or vertical orientation of the spder. By default its value is horizontal.

Option - orientation

This option indicates the horizontal or vertical orientation of the spder. By default its value is horizontal.

Syntax

$( ".selector" ).spder(
   { "option", "orientation" }
);
6

This option specifies whether the spder represents a range. By default its value is false.

Option - range

This option specifies whether the spder represents a range. By default its value is false.

This can be of type −

    Boolean − If specified as true, and the spder has exactly two handles, an element that can be styled is created between the handles.

    String

    Can be min or max. If specified creates a range element from the handle to the beginning or end of the spder respectively.

Syntax

$( ".selector" ).spder(
   { range: true }
);
7

This option specifies discrete intervals between the minimum and maximum values that the spder is allowed to represent. By default its value is 1.

Option - step

This option specifies discrete intervals between the minimum and maximum values that the spder is allowed to represent. By default its value is 1.

Syntax

$( ".selector" ).spder(
   { step: 5 }
);
8

This option specifies the initial value of a single-handle spder. If there are multiple handles (see the values options), specifies the value for the first handle. By default its value is 1.

Option - value

>This option specifies the initial value of a single-handle spder. If there are multiple handles (see the values options), specifies the value for the first handle. By default its value is 1.

Syntax

$( ".selector" ).spder(
   { value: 10 }
);
9

This option is of type Array and causes multiple handles to be created and specifies the initial values for those handles. This option should be an array of possible values, one for each handle. By default its value is null.

Option - values

This option is of type Array and causes multiple handles to be created and specifies the initial values for those handles. This option should be an array of possible values, one for each handle. By default its value is null.

Syntax

$( ".selector" ).spder(
   { values: [ 10, 25 ] }
);

The following section will show you a few working examples of spder functionapty.

Default Functionapty

The following example demonstrates a simple example of spder functionapty, passing no parameters to the spder() method.

<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <title>jQuery UI Spder functionapty</title>
      <pnk href = "https://code.jquery.com/ui/1.10.4/themes/ui-pghtness/jquery-ui.css"
         rel = "stylesheet">
      <script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
      <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

      <!-- Javascript -->
      <script>
         $(function() {
            $( "#spder-1" ).spder();
         });
      </script>
   </head>
   
   <body>
      <!-- HTML --> 
      <span id = "spder-1"></span>
   </body>
</html>

Let us save the above code in an HTML file spderexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −