Open In App

script.aculo.us Sliders Axis Option

Improve
Improve
Like Article
Like
Save
Share
Report

The script.aculo.us library is a cross-browser library that aims to improving the user interface of a website. The Slider controls are thin tracks that allow the user to input values. It is done by defining a range of values that can be selected by the user by dragging the handle to the appropriate value.

The Sliders Axis option is used to define the axis or direction that the slider is supposed to move in. This option accepts a string value that can be set to ‘horizontal’ or ‘vertical’ depending on the direction required.

Syntax:

{ axis : horizontal | vertical }

Values: This option has two values as mentioned above and described below:

  • horizontal: This would define the direction of the slider to be horizontal. It is the default value.
  • vertical: This would define the direction of the slider to be vertical.

Example 1:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <!-- Include the required scripts -->
    <script type="text/javascript" 
        src="prototype.js">
    </script>
  
    <script type="text/javascript" 
src="scriptaculous.js?load = slider">
    </script>
  
    <!-- Style the Sliders so that they
        are properly visible -->
    <style type="text/css">
        .track {
            width: 250px;
            background-color: gray;
            height: 5px;
            position: relative;
        }
  
        .track .handle {
            width: 20px;
            height: 10px;
            background-color: green;
            cursor: move;
            position: absolute;
            top: -2px;
        }
  
        .pad {
            padding: 25px;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
  
    <h2>Sliders axis</h2>
  
    <p>
        The slider is on the 
        horizontal axis.
    </p>
  
    <div class="pad">
        <div id="track-hor" class="track">
            <div id="handle-hor" class="handle">
            </div>
        </div>
    </div>
  
    <p>Current Slider Value:
        <span id="out">0</span>
    </p>
  
    <script type="text/javascript">
        new Control.Slider('handle-hor',
            'track-hor', {
            range: $R(1, 100),
  
            // Set the axis of the slider
            // to be horizontal 
            axis: 'horizontal',
  
            onSlide: (val) => {
                document.querySelector("#out")
                    .textContent = val;
            }
        });
    </script>
</body>
  
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <!-- Include the required scripts -->
    <script type="text/javascript" 
        src="prototype.js">
    </script>
  
    <script type="text/javascript" 
src="scriptaculous.js?load = slider">
    </script>
  
    <!-- Style the Sliders so that they
        are properly visible -->
    <style type="text/css">
        .track {
            width: 5px;
            background-color: gray;
            height: 150px;
            position: relative;
        }
  
        .track .handle {
            width: 20px;
            height: 10px;
            background-color: green;
            cursor: move;
            position: absolute;
            left: -8px;
        }
  
        .pad {
            padding: 25px;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
  
    <h2>Sliders axis</h2>
  
    <p>The slider is on the vertical axis.</p>
  
    <div class="pad">
        <div id="track-vert" class="track">
            <div id="handle-vert" class="handle">
            </div>
        </div>
    </div>
  
    <p>Current Slider Value:
        <span id="out">0</span>
    </p>
  
  
    <script type="text/javascript">
  
        new Control.Slider('handle-vert',
            'track-vert', {
            range: $R(1, 100),
  
            // Set the axis of the slider
            // to be vertical 
            axis: 'vertical',
  
            onSlide: (val) => {
                document.querySelector("#out")
                    .textContent = val;
            }
        });
    </script>
</body>
  
</html>


Output:



Last Updated : 20 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads