Yahoo! UI Library - Slider Widget : Slider « GUI Components « JavaScript DHTML






Yahoo! UI Library - Slider Widget


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Yahoo! UI Library - Slider Widget</title>
<link rel="stylesheet" type="text/css" href="./examples/slider/css/screen.css">

<!-- Nav and logger start -->

<script type="text/javascript" src="./build/yahoo/yahoo.js" ></script>
<script type="text/javascript" src="./build/event/event.js" ></script>
<script type="text/javascript" src="./build/logger/logger.js" ></script>
<script type="text/javascript" src="./build/dom/dom.js" ></script>
<script type="text/javascript" src="./build/animation/animation.js" ></script>
<script type="text/javascript" src="./build/dragdrop/dragdrop.js" ></script>
<script type="text/javascript" src="./examples/slider/js/color.js" ></script>
<script type="text/javascript" src="./examples/slider/js/key.js" ></script>

<script type="text/javascript" src="./build/slider/slider-debug.js" ></script></head>
<body> 
<div id="pageTitle"><h3>Slider Widget</h3></div> 

<div id="container">
  <div id="containerTop">
    <div id="header"><img id="ylogo" src="./examples/slider/img/logo.gif" /></div>
  <div id="main">


    <!-- Nav and logger start -->

<style type="text/css">
    #logButtonHeader input { font-size: 80% }

/* logger default styles */
/* font size is controlled here: default 77% */
#yui-log {position:absolute;top:1em;right:1em;font-size:77%;text-align:left;}
/* width is controlled here: default 31em */
.yui-log {background-color:#AAA;border:1px solid black;font-family:monospace;z-index:9000;}
.yui-log p {margin:1px;padding:.1em;}
.yui-log button {font-family:monospace;}
.yui-log .yui-log-hd {padding:.5em;background-color:#575757;color:#FFF;}
/* height is controlled here: default 20em*/
.yui-log .yui-log-bd {width:100%;height:20em;background-color:#FFF;border:1px solid gray;overflow:auto;}
.yui-log .yui-log-ft {margin-top:.5em;margin-bottom:1em;}
.yui-log .yui-log-ft .yui-log-categoryfilters {}
.yui-log .yui-log-ft .yui-log-sourcefilters {width:100%;border-top:1px solid #575757;margin-top:.75em;padding-top:.75em;}
.yui-log .yui-log-btns {position:relative;float:right;bottom:.25em;}
.yui-log .yui-log-filtergrp {margin-right:.5em;}
.yui-log .info {background-color:#A7CC25;} /* A7CC25 green */
.yui-log .warn {background-color:#F58516;} /* F58516 orange */
.yui-log .error {background-color:#E32F0B;} /* E32F0B red */
.yui-log .time {background-color:#A6C9D7;} /* A6C9D7 blue */
.yui-log .window {background-color:#F2E886;} /* F2E886 tan */


</style>

<div id="rightbar">
  <div id="rightBarPad">
    <h3>Links</h3>
    <script type="text/javascript">

    YAHOO.example.logApp = function() {
        return {
            init: function() {
                if (YAHOO.widget.Logger) {
                    var reader = new YAHOO.widget.LogReader( "logDiv", 
                            { newestOnTop: true, height: "400px" } );

                    reader._onClickPauseBtn(null, reader);
                }
            }
        };
    } (); 

    YAHOO.util.Event.on(window, "load", YAHOO.example.logApp.init);
    </script>

    <div id="logDiv"></div>

  </div>
</div>
<!-- Nav and logger end -->
 

    <div id="content"> 
      <div class="newsItem"> 
      <h3>Slider</h3>
        <p>
              This example uses a scale factor to convert pixels into
              a "real" value.
        </p>
              <p>
<strong>The logger is paused for performance reasons.  Click "Resume" to re-enable it.</strong>
</p>

              <div id="vertWrapper">
                <div
                 tabindex="0" 
                 id="vertBGDiv"
                 name="vertBGDiv"
                 title="Vertical Slider">
                   <div id="vertHandleDiv"><img alt="" src="./examples/slider/img/vertSlider.png" /></div> 
                </div>

                <div id="vertValueDiv">
                  <form name="formV" id="formV">
                      <input name="vertVal" id="vertVal" type="text" value="0" size="4" maxlength="4" />
                      <input id="vertButton" type="button" value="Update" />
                  </form>
                </div>
              </div>
              <div>
              <input id="re2" type="button" value="removeTicks" />
              </div>
    </div> 

    </div>
  </div>
</div>


<script type="text/javascript">

// YAHOO.widget.SliderThumb.prototype.toString = function () { 
    // return "ASDF";
// }

YAHOO.example.SliderApp = function() {
  var verticalSlider;

    // The slider can move 0 pixels up
    var topConstraint = 0;

    // The slider can move 200 pixels down
    var bottomConstraint = 200;

    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor = 1.5;

    return {

        init: function() {

            YAHOO.util.Event.addListener("formV", "submit", this.updateVert);
            YAHOO.util.Event.addListener("vertButton", "click", this.updateVert);

            verticalSlider = YAHOO.widget.Slider.getVertSlider("vertBGDiv", 
                             "vertHandleDiv", topConstraint, bottomConstraint, 20);

            verticalSlider.onChange = function(offsetFromStart) {
                // use the scale factor to convert the pixel offset into a
                // real value
                var actualValue = parseInt(offsetFromStart * scaleFactor, 10);
                document.getElementById("vertVal").value = actualValue;
                document.getElementById("vertBGDiv").title = 
                            "Vertical Slider, value = " + actualValue;
            };

            verticalSlider.onSlideStart = function() {
                YAHOO.log("slidestart");
            };

            verticalSlider.onSlideEnd = function() {
                YAHOO.log("slideend");
            };

            // verticalSlider.unreg();
            // verticalSlider.backgroundEnabled = false;

            verticalSlider.setValue(20);

        },

        updateVert: function() {
            var v = parseFloat(document.forms['formV']['vertVal'].value, 10);
            if ( isNaN(v) ) v = 0;

            // convert the real value into a pixel offset
            verticalSlider.setValue(Math.round(v/scaleFactor));
            return false;
        },

        clearConstraints: function() {
            verticalSlider.getThumb().clearConstraints();
        },

        clearTicks: function() {
            verticalSlider.getThumb().clearTicks();
        }
    };
} ();

//YAHOO.example.SliderApp.init();
YAHOO.util.Event.addListener(window, "load", YAHOO.example.SliderApp.init, 
                             YAHOO.example.SliderApp, true);
YAHOO.util.Event.addListener("re2", "click", YAHOO.example.SliderApp.clearTicks);
</script>

</body>
</html>

           
       








yui.zip( 3,714 k)

Related examples in the same category

1.Slider: vertical and horizontal, tick mark, animate the movement of the thumb
2.Yahoo! UI Library - Slider Widget 2: animate the movement of the thumb
3.Yahoo! UI Library - Slider Widget 3:
4.The RGB slider implements three slider controls to generate a RGB color
5.Slider for color picker