4 https://bugzilla.mozilla.org/show_bug.cgi?id=886646
8 <title>Test for Bug
886646</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
11 <style type=
"text/css">
16 border: 10px solid black
;
33 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=886646">Mozilla Bug
886646</a>
37 <div id=
"sticky"></div>
42 <script type=
"application/javascript">
45 /** Test for Bug
886646 - Offsets for sticky positioning, when accessed through
46 * getComputedStyle(), should be accurately computed. In particular,
47 * percentage offsets should be computed in terms of the scroll container's
50 // Test that percentage sticky offsets are computed in terms of the
51 // scroll container's content box
59 var scroller = document.getElementById(
"scroller");
60 var container = document.getElementById(
"container");
61 var sticky = document.getElementById(
"sticky");
62 var cs = getComputedStyle(sticky,
"");
64 for (var prop in offsets) {
65 sticky.style[prop] = offsets[prop] +
"%";
66 is(cs[prop], offsets[prop] +
"px");
69 // ... even in the presence of scrollbars
70 scroller.style.overflow =
"scroll";
71 container.style.width =
"100%";
72 container.style.height =
"100%";
74 var ccs = getComputedStyle(container,
"");
76 function isApproximatelyEqual(a, b) {
77 return Math.abs(a - b) <
0.001;
80 for (var prop in offsets) {
81 sticky.style[prop] = offsets[prop] +
"%";
82 var basis = parseFloat(ccs[prop ==
"left" || prop ==
"right" ?
83 "width" :
"height"]) /
100;
84 ok(isApproximatelyEqual(parseFloat(cs[prop]), offsets[prop] * basis));