马黑PHP整站系统

1234567
891011121314
15161718192021
22232425262728
293031    

[复位日记]

最新评论

风云
悄然
飞飞
马黑
悄然

网站统计

·今日访问 : 21
·页面点击 : 25
·当前在线 : 7

2026年3月2日 星期一[阅读 56]

获取滚动条宽度的方法

  function getScrollbarWidth() {
  // 创建一个临时div来测量
  const outer = document.createElement('div');
  outer.style.visibility = 'hidden';
  outer.style.overflow = 'scroll'; // 强制显示滚动条
  outer.style.width = '100px';
  document.body.appendChild(outer);

  const inner = document.createElement('div');
  inner.style.width = '100%';
  outer.appendChild(inner);

  // 计算滚动条宽度
  const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;

  // 清理
  outer.parentNode.removeChild(outer);

  return scrollbarWidth;
}


console.log('真实滚动条宽度:', getScrollbarWidth());

2026': 前一则  下一则    

发表评论:

       

Copyright © 2023 All Right Reserved 马黑PHP文章管理整站系统v1.8
联系我们: gxblk@163.com