javascript - 两个水平滚动条

标签 javascript css asp.net-mvc html codepen

当我从代码笔中嵌入日历小部件时,我的网站上有两个滚动条 https://codepen.io/jpag82/pen/Nazayx/

两个滚动条

enter image description here

一个滚动条移动正文,另一个滚动条移动整个页面,就像我使用 asp.net mvc5 一样,所以我从共享布局调用页眉页脚和侧边栏。使用

overflow-y: hidden;

只是隐藏主页面的滚动条。

在这里你可以看到单个滚动条的图像,它只是移动内部主体

单卷

enter image description here

如何去除移动内部body的滚动条?

最佳答案

问题是,日历小部件的内部容器具有固定高度,并且设置为在溢出时滚动。解决您的问题的方法是将内部容器的固定高度更改为“height: auto”。

以下面的代码为例,widget-container 在 css 中有一个固定的高度,所以它会在溢出时创建自己的滚动条,但是当你点击按钮时,高度会切换为“自动”,所以内部滚动条消失了,现在所有的滚动都在 body 上:请注意单击按钮时 body 滚动条是如何缩小的。

这应该可以解决您的问题。

var btn = document.getElementById('btn');
var widgetContainer = document.getElementById("widget-container");
var hasFixedHeight = true;
btn.addEventListener("click", function(evt) {
    if (hasFixedHeight) {
       widgetContainer.classList.add("height-auto");
       hasFixedHeight = false;
    } else {
      widgetContainer.classList.remove("height-auto");
      hasFixedHeight = true;
    }
});
body {
  overflow: auto;
  font-size: 20px;
}

.fixed-container {
  height: 500px;
  font-size: 18px;
  overflow: auto;
  margin: 15px 0;
}

.height-auto {
  height: auto;
}

.content {
  font-size: 15px;
  height: 1000px;
  margin: 15px 0;
  padding: 10px;
}
  
<body>
  Here is body, parent container of everything.
  <div id="widget-container" class="fixed-container">
    Here is the parent container to the calendar widgets
    <button id="btn" type="button">toggle scrollbar</button>
    <div class="content">
      Here is where the content, that is, your calendar widgets will be.
    </div>
  </div>
</body>

关于javascript - 两个水平滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51608835/

相关文章:

c# - Javascript函数无法到达其他函数?

c# - ASP.NET,MVC4,授权: users should see only own content

javascript - 如何在 jQuery 中检测文本输入框中的更改

javascript - 带有 SetTimeout 的简单 jQuery 付费墙

javascript - 如何使用 Javascript 在 d3 中使用 forEach

html - 调整图像大小以适应具有最大宽度集的 div

javascript - 如何使用 jQuery 制作下拉菜单

html - 媒体查询取消链接 IE8 样式表

c# - Controller 收不到来自json的数据

javascript - ajax 调用中不存在所需的防伪表单字段 “__RequestVerificationToken”