51 lines
2.8 KiB
HTML
51 lines
2.8 KiB
HTML
<html>
|
|
<head>
|
|
<script>
|
|
function print(message)
|
|
{
|
|
var paragraph = document.createElement("p");
|
|
paragraph.appendChild(document.createTextNode(message));
|
|
document.getElementById("console").appendChild(paragraph);
|
|
}
|
|
function test()
|
|
{
|
|
if (window.testRunner)
|
|
testRunner.dumpAsText();
|
|
|
|
var statik = document.getElementById('static');
|
|
var relative = document.getElementById('relative');
|
|
var firstFixed = document.getElementById('fixed1');
|
|
var secondFixed = document.getElementById('fixed2');
|
|
var body = document.body;
|
|
print("First Fixed offsetParent (null): "+firstFixed.offsetParent);
|
|
print("First Fixed offsetTop (10): "+firstFixed.offsetTop);
|
|
print("First Fixed offsetLeft (20): "+firstFixed.offsetLeft);
|
|
print("Second Fixed offsetParent (null): "+secondFixed.offsetParent);
|
|
print("Second Fixed offsetTop (15): "+secondFixed.offsetTop);
|
|
print("Second Fixed offsetLeft (30): "+secondFixed.offsetLeft);
|
|
print("Body offsetParent (null): "+body.offsetParent);
|
|
print("Body offsetTop (0): "+body.offsetTop);
|
|
print("Body offsetLeft (0): "+body.offsetLeft);
|
|
print("Static offsetParent ([object HTMLBodyElement]): "+statik.offsetParent);
|
|
print("Static offsetTop (15): "+statik.offsetTop);
|
|
print("Static offsetLeft (15): "+statik.offsetLeft);
|
|
print("Relative offsetParent ([object HTMLBodyElement]): "+relative.offsetParent);
|
|
print("Relative offsetTop (13): "+relative.offsetTop);
|
|
print("Relative offsetLeft (19): "+relative.offsetLeft);
|
|
}
|
|
</script>
|
|
</head>
|
|
<body onload="test()" style="margin:10px;border:5px solid white">
|
|
<div id="static" style="border:1px solid green"></div>
|
|
<div id="relative" style="position:relative;top:-4px;left:4px;border:1px solid blue"></div>
|
|
<div id="fixed1" style="position:fixed;top:10px;left:20px;border:1px solid red"></div>
|
|
<div id="absolute" style="position:absolute"><div id="fixed2" style="position:fixed;top:15px;left:30px"></div></div>
|
|
<p>This test checks if <code>offsetParent</code> is always <code>null</code> when accessed from the HTML <code><body></code> and from elements with CSS property <code>position:fixed</code>. To ensure values match layout, this test also checks <code>offsetTop</code> and <code>offsetLeft</code>.</p>
|
|
<p>In addition to the HTML <code><body></code>, two elements with CSS property <code>position:fixed</code> are tested: One within the body, and one within an element with CSS property <code>position:absolute</code>.</p>
|
|
<p>Finally, a static- and relative-positioned element are tested for sanity and spec adherence.</p>
|
|
<p>Expected values are parenthesized. Test has passed if all values match.</p>
|
|
<hr>
|
|
<div id="console"></div>
|
|
</body>
|
|
</html>
|