All files / src/_util get-scrollbar-size.ts

100% Statements 16/16
75% Branches 3/4
100% Functions 2/2
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 384x     1x 1x       1x 1x                     1x 1x       1x 1x   1x 1x 1x 1x   1x   1x    
let size = 0;
 
export function getScrollBarSize() {
  size = size || getSize();
  return size;
}
 
function getSize() {
  const outer = document.createElement("div");
  Object.assign(outer.style, {
    position: "absolute",
    top: "0px",
    left: "0px",
    visibility: "hidden",
    width: "200px",
    height: "150px",
    overflow: "hidden",
    pointerEvents: "none",
  });
 
  const inner = document.createElement("p");
  Object.assign(inner.style, {
    width: "100%",
    height: "200px",
  });
  outer.appendChild(inner);
  document.body.appendChild(outer);
 
  const w1 = inner.offsetWidth;
  outer.style.overflow = "scroll";
  let w2 = inner.offsetWidth;
  Eif (w1 === w2) w2 = outer.clientWidth;
 
  document.body.removeChild(outer);
 
  return w1 - w2;
}