如何禁用或隐藏 Ionic 2 中的滚动条

2024-04-01

我有一个包含在 Ionic 2 中的 Angular 2 应用程序。我正在使用<ion-tabs>,并且每个选项卡内都有一个<ion-content>。该区域的内容需要可滚动,但 Ionic 2 添加了一个我不想显示的滚动条。看来,编译时,<ion-content> has a <scroll-content>注入其中。我不想要这种行为。

我已经尝试了很多解决方案used to在 Ionic 1 中工作,但在 Ionic 2 中不起作用:

  • Setting scroll="false" on the <ion-content>
  • Setting scrollbar-y="false" on the <ion-content>
  • Setting overflow-scroll="false" on the <ion-content>
  • 在css中设置如下:

    .scroll-bar-indicator { display: none; }

etc...

设置以下内容实际上确实可以删除滚动条,但我不想劫持浏览器行为,并且它还会从内部内容中删除滚动条<ion-content>标签,我不想要这个。

::-webkit-scrollbar,
*::-webkit-scrollbar {
  display: none;
}

他们有一个类,应该能够使用:

 import { App } from 'ionic-angular';

 constructor(private app: App) {
   app.setScrollDisabled(true);
};

查看论坛讨论here https://github.com/driftyco/ionic/issues/7644/#issuecomment-238937901。但之后似乎就停止工作了2.0.0-rc.1我相信这与this https://github.com/driftyco/ionic/blob/master/CHANGELOG.md#new-behavior-of-icons-in-buttons在他们的变更日志当他们将很多属性更改为类时(即scroll-content to .scroll-content)和app.setScrollDisabled(true);尚未更新以反映其中一些更改。

如果您使用2.0.0-rc.2 or 2.0.0-rc.3我不相信<ion-content overflow-scroll="false"> or <ion-content ion-fixed>都可以工作,所以从现在开始创建你自己的类。

所以如果你在2.0.0-rc.2 or 2.0.0-rc.3您应该能够通过将其添加到您的.scss

.no-scroll .scroll-content{
     overflow: hidden;
}

并将此类添加到您的ion-content像这样

<ion-content class="no-scroll">
..
</ion-content>

所以现在请留意此后的版本中是否已修复此问题2.0.0-rc.3.


更新(2.0.0-rc.6):看起来他们做了App模块setDisableScroll函数私有(如所见here https://github.com/driftyco/ionic/commit/7b2a6d523ebdf7898ffed90d9c2574a15e8d09f0)

另外,这里还有可用功能的完整列表App模块(按版本):

  • 2.0.0-rc.1 http://ionicframework.com/docs/v2/2.0.0-rc.1/api/components/app/App/#setScrollDisabled (has 设置滚动禁用)

  • 2.0.0-rc.2 http://ionicframework.com/docs/v2/2.0.0-rc.2/api/components/app/App/#setScrollDisabled (has 设置滚动禁用)

  • 2.0.0-rc.3 http://ionicframework.com/docs/v2/2.0.0-rc.3/api/components/app/App/#setScrollDisabled (has 设置滚动禁用)

  • 2.0.0-rc.4 http://ionicframework.com/docs/v2/api/components/app/App/ (no 设置滚动禁用,并且别无选择)

  • 2.0.0-rc.5 http://ionicframework.com/docs/v2/api/components/app/App/(仍然没有设置滚动禁用或替代方案)

  • 2.0.0-rc.6 http://ionicframework.com/docs/v2/api/components/app/App/ (no 设置滚动禁用,别无选择,但他们做了更多的视图触发功能,例如viewWillUnload)

因此,除非他们把它带回来,否则请继续使用以下内容:

.无滚动 .滚动内容{ 溢出:隐藏; }

另外,我很喜欢他们的互联网点,所以如果你觉得这有帮助,请点赞。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何禁用或隐藏 Ionic 2 中的滚动条 的相关文章

随机推荐