tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

svg-viewbox.html (1882B)


      1 <!DOCTYPE html>
      2 <title>IntersectionObserver observing an SVG &lt;rect> element with changing 'transform'</title>
      3 <meta name="viewport" content="width=device-width,initial-scale=1">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="resources/intersection-observer-test-utils.js"></script>
      7 <svg id="container" width="10" height="10" viewBox="0 0 128 128" style="background: lightblue; position: absolute; top: 0; left: 0;">
      8    <rect id="target" x="0" y="0" width="128" height="128" fill="green"></rect>
      9 </svg>
     10 <script>
     11 const viewportWidth = document.documentElement.clientWidth;
     12 const viewportHeight = document.documentElement.clientHeight;
     13 setup(() => {
     14  window.entries = [];
     15  window.target = document.getElementById("target");
     16  window.targetRect = target.getBoundingClientRect();
     17 });
     18 runTestCycle(function() {
     19  assert_true(!!target, "target exists");
     20  const observer = new IntersectionObserver(function(changes) {
     21    entries = entries.concat(changes);
     22  }, {root: container, threshold: [0, 0.5, 1]});
     23  observer.observe(target);
     24  entries = entries.concat(observer.takeRecords());
     25  assert_equals(entries.length, 0, "No initial notifications");
     26  runTestCycle(step0, "First rAF.");
     27 });
     28 function step0() {
     29  target.setAttribute('y', '-64');
     30  runTestCycle(step1, "change target's y property to -64)");
     31  // The numbers in brackets are target client rect; intersection rect;
     32  // and root bounds.
     33  checkLastEntry(entries, 0, [
     34    0, targetRect.width, 0, targetRect.height,
     35    0, targetRect.width, 0, targetRect.height,
     36    0, 10, 0, 10,
     37    true,
     38  ]);
     39 }
     40 function step1() {
     41  target.style.transform = "translate(0, 50px)";
     42  checkLastEntry(entries, 1, [
     43    0, targetRect.width, -5, -5 + targetRect.height,
     44    0, targetRect.width, 0, -5 + targetRect.height,
     45    0, 10, 0, 10,
     46    true,
     47  ]);
     48 }
     49 </script>