【问题标题】:How to scroll the menu, without scrolling the content of the page in the background?如何滚动菜单,而不在后台滚动页面内容?
【发布时间】:2018-01-18 20:37:11
【问题描述】:

在我的网站上,右侧有一个菜单。当我向下滚动菜单并向下滚动时,背景页面也会滚动。

我希望后台页面不滚动。如何做到这一点?

这是我网站的一个页面,点击右边的菜单:

https://www.s1biose.com/recette

【问题讨论】:

标签: css twitter-bootstrap scroll navigation


【解决方案1】:

您可以通过多种方式禁用滚动:

使用 CSS:

$('html, body').css({
    overflow: 'hidden',
    height: '100%'
});

这将禁用滚动并将您带到页面顶部。

或者,您可以使用 JavaScript (jQuery) 来:

$(document).ready(function(){
  $(".navbar-toggle-second[aria-expanded='false']").click(function(e) {
    e.preventDefault();
    $("body").css("overflow", "hidden");
  });

  $(".navbar-toggle-second[aria-expanded='true']").click(function(e) {
    e.preventDefault();
    $("body").css("overflow", "auto");
  });
});

有关更多信息,请参阅:

How to programmatically disable page scrolling with jQuery

【讨论】:

  • 我要做的是阻止折叠菜单后面的内容滚动。菜单打开时。
  • 以下代码在我的菜单中看起来不错forum.webflow.com/t/…,我应该在我的 JS 文件中放入什么?
  • 我已经编辑了代码,所以它应该适用于您的情况。确保包含 jQuery
  • 我想做的是当菜单打开时,后面的内容不能滚动,不能点击,必须变暗。
  • 我希望行为是模态的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 2018-09-23
  • 1970-01-01
  • 2019-06-09
  • 1970-01-01
相关资源
最近更新 更多