最近看到--计算浏览器滚动条在各浏览器的宽度

从这里浏览到的

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  // 计算浏览器滚动条在各浏览器的宽度
  const scrollContainer = document.createElement('div');
  const scrollContent = document.createElement('div');
  scrollContainer.style = 'position:fixed;z-index:-1;width:50px;height:50px;overflow:scroll;';
  scrollContent.style = 'height:100px;';
  scrollContainer.append(scrollContent);
  document.body.append(scrollContainer);
  const scrollBarWidth = scrollContainer.offsetWidth - scrollContent.offsetWidth;
  console.log(scrollBarWidth)
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_41869039/article/details/88862504