| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>030a getBoundingClientRect</title>
- <style>
- html, body { margin: 0; padding: 0; background: #ffffff; color: #202020; }
- body { font-family: sans-serif; font-size: 13px; padding: 10px; }
- h1 { font-size: 20px; margin: 0 0 6px 0; }
- p { margin: 0 0 10px 0; }
- #box { width: 200px; height: 40px; background: #cc3333; }
- #below { height: 20px; background: #333333; color: #ffffff; }
- #stage { width: 300px; height: 100px; background: #eeeeee; margin-top: 10px; }
- #abs { position: absolute; left: 20px; top: 10px; width: 50px; height: 30px; background: #2244cc; }
- #pic { width: 100px; height: 60px; margin-top: 10px; }
- #result { margin-top: 12px; padding: 8px; background: #eeeeee; font-family: monospace; font-weight: bold; }
- </style>
- </head>
- <body>
- <h1>030a · getBoundingClientRect</h1>
- <p>The result must say PASS. This page exercises block, absolute and image boxes.</p>
- <div id="box"></div>
- <div id="below">below</div>
- <div id="stage"><div id="abs"></div></div>
- <img id="pic" src="PIC.BMP" alt="pic">
- <div id="result">checking...</div>
- <script>
- function near(a, b) { return Math.abs(a - b) <= 2; }
- function check() {
- var box = document.getElementById('box').getBoundingClientRect();
- var below = document.getElementById('below').getBoundingClientRect();
- var stage = document.getElementById('stage').getBoundingClientRect();
- var abs = document.getElementById('abs').getBoundingClientRect();
- var pic = document.getElementById('pic').getBoundingClientRect();
- var ok = near(box.width, 200) && near(box.height, 40) &&
- near(box.right - box.left, 200) &&
- near(below.top - box.bottom, 0) &&
- near(abs.width, 50) && near(abs.height, 30) &&
- near(abs.left - stage.left, 20) &&
- near(abs.top - stage.top, 10) &&
- near(pic.width, 100) && near(pic.height, 60);
- document.getElementById('result').textContent = ok ? 'PASS: rects match' :
- ('FAIL: box=' + box.width + 'x' + box.height +
- ' gap=' + (below.top - box.bottom) +
- ' abs=' + (abs.left - stage.left) + ',' + (abs.top - stage.top) +
- ' stageTop=' + stage.top + ' absTop=' + abs.top +
- ' pic=' + pic.width + 'x' + pic.height);
- }
- setInterval(check, 500);
- </script>
- </body>
- </html>
|