scrollfloater.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2008 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. <!--
  9. -->
  10. <head>
  11. <title>ScrollFloater</title>
  12. <script src="../base.js"></script>
  13. <script>
  14. goog.require('goog.dom');
  15. goog.require('goog.events');
  16. goog.require('goog.ui.ScrollFloater');
  17. goog.require('goog.ui.ToggleButton');
  18. </script>
  19. <link rel="stylesheet" href="../css/button.css">
  20. <style>
  21. table {
  22. border: 1px solid black;
  23. width: 100%;
  24. height: 1500px;
  25. }
  26. .left-cell {
  27. color: black;
  28. background-color: lightgray;
  29. width: 33%;
  30. vertical-align: top;
  31. }
  32. .cell {
  33. background-color: lightblue;
  34. width: 33%;
  35. vertical-align: top;
  36. }
  37. .spacer {
  38. border: 1px solid black;
  39. height: 200px;
  40. }
  41. .goog-scrollfloater {
  42. border: 1px solid black;
  43. height: 150px;
  44. width: 90%;
  45. color: black;
  46. background-color: blue;
  47. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a4e7fc), color-stop(100%,#00aadd));
  48. background: gradient(linear, left top, left bottom, color-stop(0%,#a4e7fc), color-stop(100%,#00aadd));
  49. }
  50. #floater3 {
  51. padding-top: 500px;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <form action="javascript:void(0)">
  57. <table style="border: 1px solid black">
  58. <tr>
  59. <td class="left-cell">
  60. <div class="spacer">
  61. This content does not float.
  62. </div>
  63. <div class="spacer">
  64. This content does not float.
  65. </div>
  66. <div id="floater1">
  67. This floater is constrained within a container and has a top offset of 50px.
  68. </div>
  69. </td>
  70. <td class="cell">
  71. <div class="spacer">
  72. This content does not float.
  73. </div>
  74. <div id="floater2container">
  75. </div>
  76. </td>
  77. <td class="cell">
  78. <div class="spacer">
  79. This content does not float.
  80. </div>
  81. <!-- The purpose of this position:relative element is to ensure that
  82. we're checking more than just the offsetTop of the floating
  83. child. -->
  84. <div style="position: relative">
  85. <div id="floater3">
  86. This floater is very tall.
  87. <p>
  88. This tall floater is pinned to the bottom of the window when
  89. your window is shorter and floats at the top when it is taller.
  90. </div>
  91. </div>
  92. </td>
  93. </tr>
  94. </table>
  95. <div style="height:1500px"></div>
  96. <p>This is the bottom of the page.</p>
  97. </form>
  98. <script>
  99. var parentForm = document.getElementsByTagName('form')[0];
  100. var scrollfloater1 = new goog.ui.ScrollFloater();
  101. var button1 = new goog.ui.ToggleButton("Enable Floater 1");
  102. button1.render(goog.dom.getElement('floater1'));
  103. scrollfloater1.setViewportTopOffset(50);
  104. scrollfloater1.setContainerElement(goog.dom.getElement('floater1').parentElement);
  105. scrollfloater1.decorate(goog.dom.getElement('floater1'));
  106. var scrollfloater2 = new goog.ui.ScrollFloater();
  107. var button2 = new goog.ui.ToggleButton("Enable Floater 2");
  108. scrollfloater2.addChild(button2, true);
  109. scrollfloater2.render(goog.dom.getElement('floater2container'));
  110. var scrollfloater3 = new goog.ui.ScrollFloater();
  111. scrollfloater3.decorate(goog.dom.getElement('floater3'));
  112. function setupClickHandler(ctrl, floater) {
  113. goog.events.listen(ctrl, goog.ui.Component.EventType.ACTION,
  114. function() {
  115. floater.setScrollingEnabled(ctrl.isChecked());
  116. });
  117. }
  118. button1.setState(goog.ui.Component.State.CHECKED, true);
  119. button2.setState(goog.ui.Component.State.CHECKED, true);
  120. setupClickHandler(button1, scrollfloater1);
  121. setupClickHandler(button2, scrollfloater2);
  122. </script>
  123. </body>
  124. </html>