function assert_fully_in_view(element) {
let rect = element.getBoundingClientRect();
ok(rect.top >= 0, `${element.id} top`);
ok(rect.bottom <= window.innerHeight, `${element.id} bottom`);
}
function run() {
is(window.scrollY, 0, "window should initially be at top");
let first = document.getElementById("first");
let second = document.getElementById("second");
let third = document.getElementById("third");
first.focus();
let firstOffset = window.scrollY;
isnot(firstOffset, 0, "we scrolled to first anchor");
ok(firstOffset + window.innerHeight > 4000, "we scrolled enough to show the anchor");
assert_fully_in_view(first);
window.scrollTo(0, 0);
second.focus();
let secondOffset = window.scrollY;
assert_fully_in_view(second);
window.scrollTo(0, 0);
third.focus();
let thirdOffset = window.scrollY;
assert_fully_in_view(third);
ok(secondOffset > firstOffset, "we scrolled the second line of the anchor into view");
ok(thirdOffset > secondOffset, "we scrolled the second line of the anchor into view");
window.scrollTo(0, 0); // make the results visible
SimpleTest.finish();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.