如何排查 css 没有滚动(草稿)

56 阅读1分钟
// 一键检查常见问题
(() => {
  const el = document.querySelector('你的元素选择器');
  const style = window.getComputedStyle(el);
  
  return {
    contentVsContainer: {
      height: `${el.scrollHeight} > ${el.clientHeight}`,
      width: `${el.scrollWidth} > ${el.clientWidth}`
    },
    overflow: style.overflow,
    dimensions: {
      specified: {
        width: style.width,
        height: style.height
      },
      actual: {
        width: `${el.offsetWidth}px`,
        height: `${el.offsetHeight}px`
      }
    },
    position: style.position,
    display: style.display,
    flexChild: el.parentElement ? window.getComputedStyle(el.parentElement).display === 'flex' : false
  };
})();