简体   繁体   English

如何动态设置AngularJS应用程序主体上的溢出

[英]How to dynamically set the overflow on the body of an AngularJS app

I am trying to dynamically set the overflow on the body of my AngularJS app. 我正在尝试在AngularJS应用的主体上动态设置溢出。 I have a sidenav that opens up and when it is open I want to disable scrolling on the body. 我有一个sidenav打开,当它打开时,我想禁止在主体上滚动。 If someone could have a look at my code and give me some hints on how to achieve this, that would be great: 如果有人可以看一下我的代码,并给我一些实现方法的提示,那就太好了:

HTML: HTML:

<body ng-controller="backgroundCtrl as background" md-theme="blue-grey" ng-style="{'overflow-y': background.lockBackgroundTrue}">

Controller: 控制器:

    controller('backgroundCtrl',function(){
        this.lockBackgroundFalse = 'auto';
        this.lockBackgroundTrue = 'hidden ';
    });

Any help with this would be greatly appreciated. 任何帮助,将不胜感激。 If this is not possible alternative methods would also be appreciated. 如果这不可能,则也将理解替代方法。 Thanks in advance. 提前致谢。

How about adding something like style="overflow:{{isEnabled?'hidden':'scroll'}}" . 如何添加诸如style="overflow:{{isEnabled?'hidden':'scroll'}}"

A more angular-way would be doing ng-style="{'overflow':isEnabled?'hidden':'scroll'}" 更加有角度的做法是进行ng-style="{'overflow':isEnabled?'hidden':'scroll'}"

You may set isEnabled on ng-click accordingly. 您可以相应地在ng-click上设置isEnabled

   <button href="#" ng-click="isEnabled=false">Enable scroll </button>
   <button href="#" ng-click="isEnabled=true">Disable scroll</button>

Demo 演示版

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM