047-script-dom-height.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!DOCTYPE html>
  2. <html lang="en" style="height: 100%">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>047 script DOM and 100% height</title>
  6. <style>
  7. html { height: 100%; }
  8. body { min-height: 100%; margin: 0; background: #ffffff; color: #202020;
  9. font-family: sans-serif; }
  10. .spacer { height: 1700px; padding: 16px; }
  11. footer { height: 150px; background: #204080; color: #ffffff;
  12. font-size: 22px; padding: 14px; }
  13. .ok { background: #c8f0c8; color: #000000; padding: 8px; font-size: 18px; }
  14. .fail { background: #ffc8c8; color: #000000; padding: 8px; font-size: 18px; }
  15. </style>
  16. </head>
  17. <body>
  18. <div class="spacer">
  19. <h1>047 &mdash; script DOM and 100% height</h1>
  20. <p>This page is taller than the window. Press <b>End</b>: the blue footer
  21. must appear. The old layout measured the page against its width, so End
  22. stopped here instead of at the bottom.</p>
  23. <div id="result" class="fail">script check pending</div>
  24. </div>
  25. <footer>
  26. <div id="footer-text">SCROLL-FAIL</div>
  27. <div id="script-result">SCRIPT-PENDING</div>
  28. </footer>
  29. <script>
  30. setTimeout(function () {
  31. var scripts = document.getElementsByTagName('script');
  32. var styles = document.getElementsByTagName('style');
  33. var ok = scripts.length >= 1 && scripts[0] && scripts[0].parentNode;
  34. ok = ok && styles.length >= 1 && styles[0] && styles[0].parentNode;
  35. var r = document.getElementById('result');
  36. if (r) {
  37. r.className = ok ? 'ok' : 'fail';
  38. r.textContent = ok ? 'SCRIPT-OK (' + scripts.length + ' script element)'
  39. : 'SCRIPT-FAIL';
  40. }
  41. var sr = document.getElementById('script-result');
  42. if (sr) sr.textContent = ok ? 'SCRIPT-OK' : 'SCRIPT-FAIL';
  43. var body = document.body.getBoundingClientRect();
  44. var foot = document.querySelector('footer').getBoundingClientRect();
  45. var ft = document.getElementById('footer-text');
  46. if (ft) {
  47. ft.textContent = 'SCROLL-OK body=' + Math.round(body.height) +
  48. ' footer=' + Math.round(foot.top);
  49. }
  50. }, 300);
  51. </script>
  52. </body>
  53. </html>