slider.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>goog.ui.Slider</title>
  10. <meta charset="utf-8">
  11. <script src="../base.js"></script>
  12. <script>
  13. goog.require('goog.dom');
  14. goog.require('goog.ui.Component');
  15. goog.require('goog.ui.Slider');
  16. </script>
  17. <link rel="stylesheet" href="css/demo.css">
  18. <style>
  19. .goog-slider-vertical,
  20. .goog-slider-horizontal {
  21. background-color: ThreeDFace;
  22. position: relative;
  23. overflow: hidden;
  24. }
  25. .goog-slider-thumb {
  26. position: absolute;
  27. background-color: ThreeDShadow;
  28. overflow: hidden;
  29. }
  30. .goog-slider-vertical .goog-slider-thumb {
  31. left: 0;
  32. height: 20px;
  33. width: 100%;
  34. }
  35. .goog-slider-horizontal .goog-slider-thumb {
  36. top: 0;
  37. width: 20px;
  38. height: 100%;
  39. }
  40. .goog-slider-disabled {
  41. background-color: lightgray
  42. }
  43. #s-h {
  44. margin-bottom: 2em;
  45. }
  46. strong {
  47. display: block;
  48. margin-bottom: 3px;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <h1>goog.ui.Slider</h1>
  54. <div id="s-h">
  55. <strong>Horizontal Slider</strong>
  56. <div id="s1" class="goog-slider" style="width: 200px; height: 20px">
  57. <!-- this line is here just to show that custom content can be added -->
  58. <div style="position:absolute;width:100%;top:9px;border:1px inset white;
  59. overflow:hidden;height:0"></div>
  60. <div class="goog-slider-thumb"></div>
  61. </div>
  62. <input type="checkbox" onclick="s.setMoveToPointEnabled(this.checked)">
  63. MoveToPointEnabled
  64. <input type="checkbox" onclick="s.setEnabled(this.checked)" checked>
  65. Enable
  66. <br>
  67. <input type="text" value="0" id="out1" style="margin-left: 0px">
  68. <input type="button" value="Set Value" onclick="setSliderValue(s, 'out1')">
  69. </div>
  70. <div id="s-v">
  71. <strong>Vertical Slider, inserted w/ script</strong>
  72. <label id="s2-label">
  73. <input type="checkbox" onclick="s2.setMoveToPointEnabled(this.checked)">
  74. MoveToPointEnabled
  75. </label>
  76. <input type="checkbox" onclick="s2.setEnabled(this.checked)" checked>
  77. Enable
  78. <br>
  79. <input type="text" value="0" id="out2" style="margin-left: 0px">
  80. <input type="button" value="Set Value" onclick="setSliderValue(s2, 'out2')">
  81. </div>
  82. <script>
  83. var el = document.getElementById('s1');
  84. var s = new goog.ui.Slider;
  85. s.decorate(el);
  86. s.addEventListener(goog.ui.Component.EventType.CHANGE, function() {
  87. document.getElementById('out1').value = s.getValue();
  88. });
  89. var s2 = new goog.ui.Slider;
  90. s2.setOrientation(goog.ui.Slider.Orientation.VERTICAL);
  91. s2.createDom();
  92. var el = s2.getElement();
  93. el.style.width = '20px';
  94. el.style.height = '200px';
  95. s2.render(document.body);
  96. s2.setStep(null);
  97. s2.addEventListener(goog.ui.Component.EventType.CHANGE, function() {
  98. document.getElementById('out2').value = s2.getValue();
  99. });
  100. var label = document.getElementById('s2-label');
  101. label.parentNode.insertBefore(el, label);
  102. function toggleSliderEnable(button, slider) {
  103. var buttonValue = slider.isEnabled() ? 'Enable Slider' : 'Disable Slider';
  104. button.value = buttonValue;
  105. slider.setEnabled(!slider.isEnabled());
  106. }
  107. function setSliderValue(slider, textId) {
  108. if (document.getElementById(textId)) {
  109. var value = document.getElementById(textId).value;
  110. window.console.log(value);
  111. slider.setValue(new Number(value));
  112. }
  113. }
  114. </script>
  115. </body>
  116. </html>