简体   繁体   English

动画期间的 mat-sidenav 滚动条可见性

[英]mat-sidenav scrollbar visibility during animation

I am working with the mat-sidenav and have managed to setup a very basic one that will sit on the left side and open and close just enough to show the mat-icons.我正在使用 mat-sidenav 并设法设置了一个非常基本的,它将位于左侧并打开和关闭足以显示 mat-icons。 This part is fine and working as expected.这部分很好,按预期工作。 I have included the slide animation via css for open and close.我已经通过 css 包含了用于打开和关闭的幻灯片动画。 Now the problem is the visibility of the scrollbar during the animation.现在的问题是动画期间滚动条的可见性。 I understand why the scroll exists as this is because I am using an ngif to hide content after the mat-icon so when it is in partial closed state the letters/description of the icon does not peek on the end...this is then inserted as the animation takes place through a toggle functionality - I am perfectly fine with the scrollbar existing here.我理解为什么滚动会这样存在,因为我使用 ngif 来隐藏 mat-icon 之后的内容,所以当它处于部分关闭状态时,图标的字母/描述不会在最后看到......这就是通过切换功能在动画发生时插入 - 我对此处存在的滚动条非常满意。 My problem is with making the scrollbar invisible yet still there;我的问题是使滚动条不可见但仍然存在; the reason is that the menu could also grow vertically depending on permissions and I would like the user to be able to scroll even though they can not see the scrollbar.原因是菜单也可以根据权限垂直增长,我希望用户能够滚动,即使他们看不到滚动条。 Now this is not a new problem as I have seen after researching - however I do not understand how to apply what I have read in the below link to my problem.现在这不是我在研究后看到的新问题 - 但是我不明白如何将我在以下链接中阅读的内容应用于我的问题。 This along with something I have observed with css attribute overriding which I assume is because I am not using css scoping properly;这以及我观察到的 css 属性覆盖的一些东西,我认为这是因为我没有正确使用 css 范围; makes up my issue.弥补了我的问题。

Here is the link to the popular solution: Hide scroll bar, but while still being able to scroll这是流行解决方案的链接: 隐藏滚动条,但仍然能够滚动

Inspecting the element I find the mat-drawer-inner-container is what has the overflow property and I find that any of the properties I set via css does not take.检查元素,我发现 mat-drawer-inner-container 是具有溢出属性的元素,我发现我通过 css 设置的任何属性都没有。 Below is a very stripped version of the html for debugging and is what I am working with to try and get this to work:下面是一个非常精简的用于调试的 html 版本,这是我正在尝试使其工作的内容:

<mat-sidenav-container fullscreen>
   <mat-sidenav #sidenav mode="side" class="navbarComponent" [ngStyle]="{ 'width.em': sidenavWidth }" opened="true">

   <mat-nav-list>

      <div id="menu" class="custom-selector">
        <mat-list-item (click)="toggle()">
         <mat-icon mat-list-icon class="noselect">menu</mat-icon>
         </mat-list-item>

         <div *ngIf="sidenavWidth > 6" class="sidenav-item noselect" style="background-color:#d56a00; padding:20px 30px 20px 10px; line-height:0px; text-align:left;">
          <table width="100%">
            <tr>
              <td><img src="assets/images/avatar.png" width="100" height="100"></td>
              <td id="avatar-table" style="color:#fff; vertical-align:top; padding:10px; line-height:15px;" class="col text-truncate"><p><b>Some name</b><br/>
                   Some other text</p>
            </tr>
          </table>
        </div>

         Will use ngfor to generate all the menus. This one is just one and the Html is just a menu with hardcoded values
        <app-menu-list-item [sidenavWidth]="sidenavWidth" [subMenuEnabled]="subMenuEnabled"></app-menu-list-item>

      </div>




     </mat-nav-list>

   </mat-sidenav>


</mat-sidenav-container>

And here is the css I have tried.这是我尝试过的css。 Have used basically exactly what was in the link for the solution but as I understand it you need to wrap the element which is responsible for the scroll in another element and make that one with overflow hidden and position relative.基本上完全使用了解决方案链接中的内容,但据我所知,您需要将负责滚动的元素包装在另一个元素中,并使该元素具有溢出隐藏和相对位置。 I have attempted this wrapping using mat-sidenav as the parent/wrapper and .mat-drawer-inner-container as the child/inner element:我尝试使用 mat-sidenav 作为父/包装器和 .mat-drawer-inner-container 作为子/内部元素进行这种包装:

html, body {
    height: 99%;
    border: 1px solid red;
    overflow:hidden;
}

mat-sidenav {
    height: 100%;
    width: 100%;
    border: 1px solid green;
    overflow: hidden;
    position: relative;
}

.mat-drawer-inner-container {
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: -15px;
    border: 1px solid blue;
    overflow: auto;
}

Now for the last part...let's assume I got the above correct.现在是最后一部分......让我们假设我的上述内容是正确的。 The css does not take. css 不带。 Is this because of css scoping?这是因为 css 作用域吗? The .mat-drawer-inner-container stays the same - this is what I see after I inspect element: .mat-drawer-inner-container 保持不变 - 这是我检查元素后看到的:

.mat-drawer-inner-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

If I change the overflow element in the browser to lets say hidden just to see if it takes - it does remove the scrollbar(not what I want but a good way to test)...which should mean the way I am applying my css attributes is incorrect.如果我将浏览器中的溢出元素更改为隐藏,只是为了看看它是否需要 - 它确实删除了滚动条(不是我想要的,而是一种很好的测试方法)......这应该意味着我应用我的 css 的方式属性不对。

Yes I am quite new to frontend.是的,我对前端很陌生。 Eager to learn though it needs to be as I work on the project.渴望学习,尽管在我从事项目时需要学习。

Any advice?有什么建议吗?

EDIT: The requested screenshot.编辑:请求的屏幕截图。 The inspected element被检查的元素

The css: css:

.mat-drawer-inner-container {
    overflow-x: hidden !important;
}

your CSS is ok just add it in style.css file你的CSS 没问题,只需将它添加到style.css文件中

even try:甚至尝试:

 *{ overflow: hidden !important; } 

in style.scssstyle.scss 中

if someone having same problem this is worked for me very well如果有人遇到同样的问题,这对我很有用

::ng-deep .mat-drawer-inner-container {
     overflow: visible!important;
}

暂无
暂无

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

相关问题 让内容流出<mat-sidenav>而不是为它创建滚动条</mat-sidenav> - Let content flow outside of <mat-sidenav> instead of creating scrollbar for it 如何固定 mat-toolbar 和 mat-sidenav 并且在 mat-sidenav-content 内只有一个滚动条? - How to pin mat-toolbar and mat-sidenav and only have a scrollbar inside mat-sidenav-content? Angular 材质 - 禁用 mat-sidenav 过渡 animation 但保留儿童动画? - Angular Material - Disable mat-sidenav transition animation but keep children animations? 垫子工具栏的宽度与垫子侧面导航不匹配 - mat-toolbar not match width with mat-sidenav 由 Angular 中的子组件覆盖父样式(mat-sidenav) - Override parent style by a child compoent in Angular (mat-sidenav) Angular:mat-sidenav 在调整大小时忽略自动调整大小或模式 - Angular: mat-sidenav ignores autosize or mode on resize 除非设置了内容高度,否则不会显示 Angular mat-sidenav - Angular mat-sidenav is not showing unless content height is set 如何使可切换的 mat-sidenav 推送在 mat-sidenav-content 中也固定为 header - How to make a toggleable mat-sidenav push also a fixed header in the mat-sidenav-content 如何让 mat-sidenav 占据 mat-toolbar 下方的整个垂直空间? - How can I make mat-sidenav take up entire vertical space underneath mat-toolbar? Angular 6,7 如何将默认主题颜色应用于 mat-sidenav 背景? - Angular 6,7 How to apply default theme color to mat-sidenav background?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM