2 <script type=
"text/javascript">
4 function rectsShouldBeEqual(baseline
, other
, outputElt
)
6 if (baseline
.left
!= other
.left
||
7 baseline
.top
!= other
.top
||
8 baseline
.right
!= other
.right
||
9 baseline
.bottom
!= other
.bottom
)
10 outputElt
.innerHTML
= '<span style="color:red;"><b>FAIL<BR></b></span>' +
11 "left should be " + baseline
.left
+ " but is " + other
.left
+ "<BR>" +
12 "top should be " + baseline
.top
+ " but is " + other
.top
+ "<BR>" +
13 "right should be " + baseline
.right
+ " but is " + other
.right
+ "<BR>" +
14 "bottom should be " + baseline
.bottom
+ " but is " + other
.bottom
;
16 outputElt
.innerHTML
= '<span style="color:green;"><b>PASS</b></span>';
19 function testGetClientBoundingRect()
21 var baseline
= document
.getElementById("baseline1");
22 var moveme
= document
.getElementById("moveme1");
24 var bounds
= baseline
.getBoundingClientRect();
25 moveme
.style
.left
= bounds
.left
;
26 moveme
.style
.top
= bounds
.top
;
27 moveme
.style
.width
= bounds
.right
- bounds
.left
;
28 moveme
.style
.height
= bounds
.bottom
- bounds
.top
;
30 var newBounds
= moveme
.getBoundingClientRect();
31 rectsShouldBeEqual(bounds
, newBounds
, document
.getElementById("results1"));
34 function testGetClientRects()
36 var baseline
= document
.getElementById("baseline2");
37 var moveme
= document
.getElementById("moveme2");
39 var boundsList
= baseline
.getClientRects();
40 moveme
.style
.left
= boundsList
[0].left
;
41 moveme
.style
.top
= boundsList
[0].top
;
42 moveme
.style
.width
= boundsList
[0].right
- boundsList
[0].left
;
43 moveme
.style
.height
= boundsList
[0].bottom
- boundsList
[0].top
;
45 var newBoundList
= moveme
.getClientRects();
46 rectsShouldBeEqual(boundsList
[0], newBoundList
[0], document
.getElementById("results2"));
51 document
.body
.style
.zoom
= "0.9";
52 testGetClientBoundingRect();
57 <body onload=
"runTest();">
59 <p>Tests that these functions account for full page zoom.
<br>There should be no red visible.
</p>
61 <table width=
"100%"><tr><td width=
"200px">getClientBoundingRect():
63 <div id=
"baseline1" style=
"position:absolute; left:100px; top:100px; width:100px; height:100px; background-color:red;"></div>
64 <div id=
"moveme1" style=
"position:absolute; left:0px; top:0px; width:50px; height:50px; background-color:green;"></div>
65 <div id=
"results1" style=
"position:absolute; left:10px; top:220px">...
</div>
67 </td><td>getClientRects():
69 <div id=
"baseline2" style=
"position:absolute; left:300px; top:100px; width:100px; height:100px; background-color:red;"></div>
70 <div id=
"moveme2" style=
"position:absolute; left:0px; top:0px; width:50px; height:50px; background-color:green;"></div>
71 <div id=
"results2" style=
"position:absolute; left:220px; top:220px">...
</div>